def set_config(config, git_urls, jira_url, github_username, jira_username, jira_email_id, jira_board, jira_project): """Set git_urls and github username""" if os.path.exists(config.config_file): os.unlink(config.config_file) try: if None not in (git_urls, github_username, jira_username, jira_email_id, jira_board, jira_project, jira_url): auth_dict = { 'kerberos': True, 'basic_auth': False, 'username': str(jira_username).encode() } content_dict = { 'url': str(jira_url).encode(), 'github_username': str(github_username).encode(), 'board': str(jira_board).encode(), 'project': str(jira_project).encode(), 'email_id': str(jira_email_id).encode(), 'auth': auth_dict, 'ca_cert_path': "/etc/ssl/certs/ca-bundle.crt", 'verify_ssl': True, 'label_check': False, 'check_for_updates': 'false' } content = set_config_properties(git_urls, content_dict) update_yaml(config.config_file, content) echo_success("Configs are set !") jira = MyJiraWrapper('config.yaml', 'labels.yaml') else: echo_error("Please Pass missing options!") except Exception as err: click.echo(err)
def start_syncing(config, interval): """Sync github issues, pr, pr_reviews as Jira tasks. Currently supported day and week interval e.g. jirasync start-syncing --interval week """ if interval not in ['week', 'day']: echo_error("Please pass correct interval. e.g. 'week', 'day'") exit(1) else: interval = configure_interval(interval) yaml_data = get_yaml_data(config.config_file) git_hub_plugin = GitHubPlugin(yaml_data['github_username'], yaml_data['email_id'], interval, yaml_data['git_urls'] ) created_issue_list = git_hub_plugin.get_github_issues_created_list() assigned_issue_list = git_hub_plugin.get_github_issues_assigned_list() pr_list = git_hub_plugin.get_opened_pull_requests() pr_closed_list = git_hub_plugin.get_pull_requests_merged_closed() pr_review_list_closed = git_hub_plugin.get_pull_requests_reviewed() pr_review_list_open = git_hub_plugin.get_pull_requests_review_in_progress() jira = MyJiraWrapper('config.yaml', 'labels.yaml') # formatting('Issues Created', created_issue_list) # formatting('Issues Assigned', assigned_issue_list) # formatting('PR Raised', pr_list) # formatting('PR Merged', pr_closed_list) # formatting('PR Reviewed Closed Status', pr_review_list_closed) # formatting('PR Reviewed Open Status', pr_review_list_open) start_issue_workflow(github_issues=created_issue_list, jira=jira) start_issue_workflow(github_issues=assigned_issue_list, jira=jira) start_create_pull_requests_workflow(github_issues=pr_list, jira=jira) start_create_pull_requests_workflow(github_issues=pr_closed_list, jira=jira) start_review_pull_requests_workflow(github_issues=pr_review_list_closed, jira=jira) start_review_pull_requests_workflow(github_issues=pr_review_list_open, jira=jira)
def check_github_history(config, interval): """See GitHub History result based on intervals e.g. jirasync check-github-history --interval week """ if interval not in ['week', 'day']: echo_error("Please pass correct interval. e.g. 'week', 'day'") exit(1) else: interval = configure_interval(interval) yaml_data = get_yaml_data(config.config_file) git_hub_plugin = GitHubPlugin(yaml_data['github_username'], yaml_data['email_id'], interval, yaml_data['git_urls'] ) issue_list = git_hub_plugin.get_github_issues_created_list() assigned_issue_list = git_hub_plugin.get_github_issues_assigned_list() pr_list = git_hub_plugin.get_opened_pull_requests() pr_closed_list = git_hub_plugin.get_pull_requests_merged_closed() pr_review_list_closed = git_hub_plugin.get_pull_requests_reviewed() pr_review_list_open = git_hub_plugin.get_pull_requests_review_in_progress() formatting('Issues Created', issue_list) formatting('Issues Assigned', assigned_issue_list) formatting('PR Raised', pr_list) formatting('PR Merged', pr_closed_list) formatting('PR Reviewed Closed Status', pr_review_list_closed) formatting('PR Reviewed Open Status', pr_review_list_open)
def formatting(header, github_list): echo_error("=================================") echo_error(header) echo_error("=================================") if len(github_list) == 0: echo_error("No new item found !") else: for item in github_list: echo_error(item.data['url']) print("\n")
def print_issue_list(issue_list): utils.echo_error( '\n=======================================Start Fetching=======================================' ) for issue_stat in issue_list: print("Title ==> " + issue_stat.title) print("Description ==> \n" + issue_stat.data['body']) print("Number ==> " + str(issue_stat.data['number'])) print("Assignees ==> " + str(len(issue_stat.data['assignees']))) print("Status ==> " + issue_stat.data['state']) print("URL ==> " + issue_stat.data['url']) print("Project ==> " + issue_stat.project) utils.echo_error('===========================================')
def start_create_pull_requests_workflow(github_issues, jira): # Create PR task if those are not created for issue in github_issues: pr_text = str('pr#' + issue.project + '#' + issue.id) tasks = jira.search_task_by_summary(text=pr_text) if len(tasks) > 1: print("Not a Valid Result! Found more than 1 tasks for" " github {}".format(pr_text)) elif len(tasks) == 1: # Issue Already Exist, Check Assignee and Status echo_error("Updating PR task for .....{}".format( issue.data['url'])) update_existing_issue_in_current_sprint(tasks[0], issue, jira=jira) elif len(tasks) == 0: # Create new issue in backlog. echo_error("Creating PR task for.....{}".format(issue.data['url'])) create_pull_request_in_current_sprint(issue, jira=jira, issue_text=pr_text) else: print("Nothing Happened")