コード例 #1
0
def handle_transition(event: dict, context) -> Dict:
    """
    Jira transition webhook handler
    :param event: AWS Lambda proxy event
    :param context: AWS context
    :return: Http response
    """
    enable_debug_logging()
    print(f"event: {json.dumps(event)}")
    body: Dict = json.loads(event['body'])
    print(f"body: {json.dumps(body)}")
    transition_event = TransitionEvent(data=body)
    properties = _get_transition_properties(transition_event)
    payload = {
        'context': Config.check_name,
        'target_url':
        f'{Config.jira_cloud_url}/browse/{transition_event.issue_key}',
        'state': properties[0],
        'description': properties[1]
    }
    print(f"payload: {json.dumps(payload)}")
    if payload:
        pull_requests = JiraClient().get_pull_requests(
            transition_event.issue_id)
        for pull_request in pull_requests['detail'][0]['pullRequests']:
            number = pull_request['id'].replace('#', '')
            url = pull_request['source']['url']
            (owner, repo, branch) = url.replace('https://github.com/',
                                                '').split('/', 2)
            r = GithubClient().get_pull_request(owner=owner,
                                                repo=repo,
                                                number=number)
            r = GithubClient().post(r['statuses_url'], payload=payload)
            print(f"github response: {json.dumps(r.json())}")
    else:
        print("No handler for event: Ignoring...")
    return {"statusCode": 200}
コード例 #2
0
import pprint
from GithubClient import GithubClient

pp = pprint.PrettyPrinter(indent=4)

g = GithubClient()
response = g.request(
    "POST",
    "/gists",
    data={
        "description": "An Example for my Talk on Consuming Web APIs with Python",
        "public": True,
        "files": {"hello_guido.py": {"content": 'print "Hello Guido!"'}},
    },
)
pp.pprint(response)
コード例 #3
0
from flask import request
import simplejson as json
from sys import stdout

from GithubClient import GithubClient

# render our special templates
app = Flask(__name__,
            static_folder="./frontend/dist/static",
            template_folder="./frontend/dist")

cors = CORS(app, resources={r"/api/*": {"origins": "*"}})

# Set up client
stdout.write("Initializing client...\n")
client = GithubClient()
stdout.write("Initializing Github client\n")


@app.route('/api/events', methods=['GET'])
def get_events():
    """
    This method accepts resume text and routes it to
    the appropriate location.
    """
    global client

    user = request.args.get('user')
    events = client.get_events_for_user(user)
    assert isinstance(events, list)
コード例 #4
0
import pprint
from GithubClient import GithubClient

pp = pprint.PrettyPrinter(indent=4)

g = GithubClient()
response = g.request("GET", "/users/%s/gists" % g.username)
pp.pprint(response)
コード例 #5
0
import pprint
from GithubClient import GithubClient

pp = pprint.PrettyPrinter(indent=4)

g = GithubClient()
response = g.request(
    "POST",
    "/gists",
    data={
        "description":
        "An Example for my Talk on Consuming Web APIs with Python",
        "public": True,
        "files": {
            "hello_guido.py": {
                "content": 'print "Hello Guido!"',
            },
        },
    })
pp.pprint(response)