Esempio n. 1
0
def install_hooks(args):
    if not args.hook_url:
        fail('No hook URL specified!')

    if not args.secret:
        fail('No hook secret specified!')

    if not args.gh_url and not args.jira_url:
        fail('Neither GitHub nor JIRA URL specified!')

    # user wants to install a github hook
    if args.gh_url:
        if not args.gh_token:
            fail('No GitHub token specified!')

        if not args.gh_org:
            fail('No GitHub organization specified!')

        github = ghlib.GitHub(args.gh_url, args.gh_token)

        if args.gh_repo:
            ghrepo = github.getRepository(args.gh_org + '/' + args.gh_repo)
            ghrepo.create_hook(url=args.hook_url, secret=args.secret)
        else:
            github.create_org_hook(url=args.hook_url, secret=args.secret)

    # user wants to install a JIRA hook
    if args.jira_url:
        if not args.jira_user or not args.jira_token:
            fail('No JIRA credentials specified!')
        jira = jiralib.Jira(args.jira_url, args.jira_user, args.jira_token)
        jira.create_hook('github_jira_synchronization_hook', args.hook_url,
                         args.secret)
Esempio n. 2
0
def check_hooks(args):
    github = ghlib.GitHub(args.gh_url, args.gh_user, args.gh_token)
    repo = github.getRepository(args.gh_org + '/' + args.gh_repo)
    #for a in repo.get_alerts():
    #    print(json.dumps(a.json, indent=2))
    a = repo.get_alert(98)
    print(json.dumps(a.json, indent=2))
Esempio n. 3
0
def sync(args):
    if not args.gh_url or not args.jira_url:
        fail('Both GitHub and JIRA URL have to be specified!')

    if not args.gh_token:
        fail('No GitHub credentials specified!')

    if not args.jira_user or not args.jira_token:
        fail('No JIRA credentials specified!')

    if not args.jira_project:
        fail('No JIRA project specified!')

    if not args.gh_org:
        fail('No GitHub organization specified!')

    if not args.gh_repo:
        fail('No GitHub repository specified!')

    github = ghlib.GitHub(args.gh_url, args.gh_token)
    jira = jiralib.Jira(args.jira_url, args.jira_user, args.jira_token)
    util.Sync(github,
              jira.getProject(args.jira_project),
              direction=direction_str_to_num(
                  args.direction)).sync_repo(args.gh_org + '/' + args.gh_repo)
Esempio n. 4
0
def list_hooks(args):
    if not args.gh_url and not args.jira_url:
        fail('Neither GitHub nor JIRA URL specified!')

    # user wants to list github hooks
    if args.gh_url:
        if not args.gh_token:
            fail('No GitHub token specified!')

        if not args.gh_org:
            fail('No GitHub organization specified!')

        github = ghlib.GitHub(args.gh_url, args.gh_token)

        if args.gh_repo:
            for h in github.getRepository(args.gh_org + '/' +
                                          args.gh_repo).list_hooks():
                print(json.dumps(h, indent=4))
        else:
            for h in github.list_org_hooks(args.gh_org):
                print(json.dumps(h, indent=4))

    # user wants to list JIRA hooks
    if args.jira_url:
        if not args.jira_user or not args.jira_token:
            fail('No JIRA credentials specified!')

        jira = jiralib.Jira(args.jira_url, args.jira_user, args.jira_token)

        for h in jira.list_hooks():
            print(json.dumps(h, indent=4))
Esempio n. 5
0
def serve(args):
    if not args.gh_url or not args.jira_url:
        fail('Both GitHub and JIRA URL have to be specified!')

    if not args.gh_token:
        fail('No GitHub token specified!')

    if not args.jira_user or not args.jira_token:
        fail('No JIRA credentials specified!')

    if not args.jira_project:
        fail('No JIRA project specified!')

    if not args.secret:
        fail('No Webhook secret specified!')

    github = ghlib.GitHub(args.gh_url, args.gh_token)
    jira = jiralib.Jira(args.jira_url, args.jira_user, args.jira_token)
    sync = util.Sync(github,
                     jira.getProject(args.jira_project),
                     direction=direction_str_to_num(args.direction))
    server.run_server(sync, args.secret, port=args.port)