def main(): args = parse_args() pagure_token = None if args.token: pagure_token = args.token elif args.token_file: with open(args.token_file, 'r') as f: pagure_token = f.read().strip() else: RuntimeError("Please specify Pagure token") message = None if args.add_comment: message = args.message.format(move_from=args.move_from, move_to=args.move_to) try: pagure = Pagure(pagure_repository=PAGURE_REPO, pagure_token=pagure_token) except TypeError: pagure = Pagure(repo_to=PAGURE_REPO, pagure_token=pagure_token) move_tickets_to_milestone(pagure, args.move_from, args.move_to, message=message)
class PagureWorker: def __init__(self, repo, api_key, log): self.api = Pagure(pagure_token=api_key, repo_to=repo) self.log = log def comment_on_issue(self, pg_issue_id, gh_issue_id, g_repo): msg = textwrap.dedent(f""" Dogtag PKI is moving from Pagure issues to GitHub issues. This means that existing or new issues will be reported and tracked through Dogtag PKI's [GitHub Issue tracker](https://github.com/{g_repo}/issues). This issue has been cloned to GitHub and is available here: https://github.com/{g_repo}/issues/{gh_issue_id} If you want to receive further updates on the issue, please navigate to the [GitHub issue](https://github.com/{g_repo}/issues/{gh_issue_id}) and click on `Subscribe` button. Thank you for understanding, and we apologize for any inconvenience. """).strip() self.log.info(f"Updating issue {pg_issue_id} with {gh_issue_id}") self.api.comment_issue(pg_issue_id, msg) def close_issue(self, pq_issue_id, status=None): # Close the status as Migrated/Fixed, only if the issue is NOT closed if self.api.issue_info(pq_issue_id)['status'].lower() == 'open': if status is None: status = "Fixed" self.log.info( f"Closing issue {pq_issue_id} with '{status}' status") self.api.change_issue_status(pq_issue_id, "Closed", status)
def run(self): pagure = Pagure( pagure_repository=PAGURE_REPO, pagure_token=self.pagure_token ) git = self._get_commits() # get all fixed tickets from the primary milestone primary_closed = query( pagure, "Closed", milestones=[self.args.milestone]) primary_fixed = filter_by_close_status(primary_closed, [u'fixed']) # get all fixed tickets from other milestones that can be possibly # fixed in this release if self.args.milestones: possibly_closed = query( pagure, "Closed", milestones=self.args.milestones) possibly_fixed = filter_by_close_status( possibly_closed, [u'fixed']) fixed_here_tickets = self._filter_tickets( possibly_fixed, git.commits) + primary_fixed else: fixed_here_tickets = primary_fixed ticket_issues = [issue.get('id') for issue in fixed_here_tickets] for commit in git.commits: if len(commit.tickets) > 0: for issue in commit.tickets: if issue not in ticket_issues: fixed_here_tickets.append(pagure.issue_info(issue)) ticket_issues.append(issue) fixed_here_tickets.sort(key=lambda x: x.get('id')) bugs = self._get_bugs(fixed_here_tickets) self._print_wiki(fixed_here_tickets, bugs, git)
def run(self): try: pagure = Pagure(pagure_repository=PAGURE_REPO, pagure_token=self.pagure_token) except TypeError: pagure = Pagure(repo_to=PAGURE_REPO, pagure_token=self.pagure_token) git = self._get_commits() if not self.args.nomilestones: # get all fixed tickets from the primary milestone primary_closed = query(pagure, "Closed", milestones=[self.args.milestone]) primary_fixed = filter_by_close_status(primary_closed, [u'fixed']) # get all fixed tickets from other milestones that can be possibly # fixed in this release if self.args.milestones: possibly_closed = query(pagure, "Closed", milestones=self.args.milestones) possibly_fixed = filter_by_close_status( possibly_closed, [u'fixed']) fixed_here_tickets = self._filter_tickets( possibly_fixed, git.commits) + primary_fixed else: fixed_here_tickets = primary_fixed else: fixed_here_tickets = [] ticket_issues = list( set([issue.get('id') for issue in fixed_here_tickets])) for commit in git.commits: if len(commit.tickets) > 0: for issue in commit.tickets: if issue not in ticket_issues: fixed_here_tickets.append(pagure.issue_info(issue)) ticket_issues.append(issue) if commit.release_note: for t in fixed_here_tickets: if str(t.get('id')) == issue: append_custom_field(t, 'changelog', commit.release_note) break fixed_tickets = {} for t in fixed_here_tickets: if t['id'] not in fixed_tickets: fixed_tickets[t['id']] = t sorted_tickets = sorted(fixed_tickets.values(), key=lambda x: x['id']) bugs = self._get_bugs(sorted_tickets) self._print_wiki(sorted_tickets, bugs, git)
def __init__(self, project, auth_token=os.getenv('PAGURE_TOKEN')): """ Creates an instance of the Pagure tracker integration. :param repo: The name of the project to work with. :type repo: str :param auth_token: Authentication token. Default: env:PAGURE_TOKEN. :type auth_token: str :raises: release_dashboard.trackers.TrackerError """ if auth_token is None: raise TrackerError('No valid token found') self.pg = Pagure(pagure_token=auth_token, pagure_repository=project)
async def pagure_message(tag, message): tags = split_bz(tag) instance_url = "https://" + tags[1] pg = Pagure(instance_url=instance_url,pagure_repository=tags[2]) issue = pg.issue_info(tags[3]) summary = "" summary += "> **{}** ({}) - Issue **{}** at **{}**\n".format(issue["user"]["fullname"], issue["user"]["name"], tags[3], tags[2]) summary += "> Status - **{}**\n".format(issue["status"]) summary += "> \n" summary += "> {}".format(issue["title"]) await message.channel.send("{}/{}/issue/{}".format(instance_url, tags[2], tags[3])) await message.channel.send(summary)
def get_pull_requests(username, repository_name): """ Returns the list of PR titles for specified username and repo from Pagure :param username: username of the user on Pagure :param repository_name: name of the repo on Pagure :returns: List of titles of PRs """ pg = Pagure() pg.repo = repository_name list_of_pull_requests = [] for pull_request in pg.list_requests(): if pull_request["user"]["name"] == username: list_of_pull_requests.append(pull_request["title"]) return list_of_pull_requests
def run(self): pagure = Pagure(pagure_repository=PAGURE_REPO, pagure_token=self.pagure_token) git = self._get_commits() # get all fixed tickets from the primary milestone primary_closed = query(pagure, "Closed", milestones=[self.args.milestone]) primary_fixed = filter_by_close_status(primary_closed, [u'fixed']) # get all fixed tickets from other milestones that can be possibly # fixed in this release if self.args.milestones: possibly_closed = query(pagure, "Closed", milestones=self.args.milestones) possibly_fixed = filter_by_close_status(possibly_closed, [u'fixed']) fixed_here_tickets = self._filter_tickets( possibly_fixed, git.commits) + primary_fixed else: fixed_here_tickets = primary_fixed bugs = self._get_bugs(fixed_here_tickets) self._print_wiki(fixed_here_tickets, bugs, git)
class PagureWorker: def __init__(self, repo, api_key, log): self.api = Pagure(pagure_token=api_key, repo_to=repo) self.log = log def comment_on_issue(self, pg_issue_id, gh_issue_id): msg = textwrap.dedent(f""" 389-ds-base is moving from Pagure to Github. This means that new issues and pull requests will be accepted only in [389-ds-base's github repository](https://github.com/389ds/389-ds-base). This issue has been cloned to Github and is available here: - https://github.com/389ds/389-ds-base/issues/{gh_issue_id} If you want to receive further updates on the issue, please navigate [to the github issue](https://github.com/389ds/389-ds-base/issues/{gh_issue_id}) and click on `subscribe` button. Thank you for understanding. We apologize for all inconvenience. """).strip() self.log.info(f"Updating issue {pg_issue_id} with {gh_issue_id}") self.api.comment_issue(pg_issue_id, msg) def close_issue(self, pq_issue_id, status=None): if status is None: status = "Fixed" self.log.info(f"Closing issue {pq_issue_id} with '{status}' status") self.api.change_issue_status(pq_issue_id, "Closed", status) def comment_on_pull_request(self, pg_pr_id, gh_issue_id): msg = textwrap.dedent(f""" 389-ds-base is moving from Pagure to Github. This means that new issues and pull requests will be accepted only in [389-ds-base's github repository](https://github.com/389ds/389-ds-base). This pull request has been cloned to Github as issue and is available here: - https://github.com/389ds/389-ds-base/issues/{gh_issue_id} If you want to continue to work on the PR, please navigate [to the github issue](https://github.com/389ds/389-ds-base/issues/{gh_issue_id}), download the patch from the attachments and file a new pull request. Thank you for understanding. We apologize for all inconvenience. """).strip() self.log.info(f"Updating PR {pg_pr_id} with {gh_issue_id}") self.api.comment_request(pg_pr_id, msg) def close_pull_request(self, pg_pr_id): self.log.info(f"Closing PR {pg_pr_id}") self.api.close_request(pg_pr_id)
class PagureTracker(Tracker): """ Implements the integration for Pagure. Example:: pg = PagureTracker('atomic-wg', auth_token='secret') issue_id = pg.create_issue('subject', 'the body\nof the ticket') """ def __init__(self, project, auth_token=os.getenv('PAGURE_TOKEN')): """ Creates an instance of the Pagure tracker integration. :param repo: The name of the project to work with. :type repo: str :param auth_token: Authentication token. Default: env:PAGURE_TOKEN. :type auth_token: str :raises: release_dashboard.trackers.TrackerError """ if auth_token is None: raise TrackerError('No valid token found') self.pg = Pagure(pagure_token=auth_token, pagure_repository=project) def create_issue(self, title, body): """ Creates an issue in an external tracker. :param title: The title of the issue. :type title: str :param body: The main body/content of the issue. :type body: str :param kwargs: Any other keyword arguments specific to the tracker. :type kwargs: dict :returns: The identifier of the new issue :rtype: str :raises: release_dashboard.trackers.TrackerError """ try: result = self.pg.create_issue(title=title, content=body) return str(result['id']) except APIError as err: raise TrackerError(*err.args)
def __init__(self, repo, api_key, log): self.api = Pagure(pagure_token=api_key, repo_to=repo) self.log = log
def main(): # grab token and connec to pagure token = os.getenv('PAGURE_TOKEN') if token: logger.info("Using detected token to talk to pagure.") pg = Pagure(pagure_token=token) else: logger.info("No pagure token was detected.") logger.info( "This script will run but won't be able to create new issues.") pg = Pagure() # Set the repo to create new issues against pg.repo = PAGURE_REPO # Used for printing out a value when the day has changed date = datetime.date.today() # Grab messages from fedmsg and process them as we go logger.info("Starting listening for fedmsgs..") for name, endpoint, topic, msg in fedmsg.tail_messages(): logger.debug(topic) # Print out a log statement if the day has changed today = datetime.date.today() if today != date: date = today logger.info('mark') if "pungi.compose.status.change" in topic: print('.', end='') # some sort of indicator of progress print('.') # some sort of indicator of progress status = msg['msg']['status'] # If we are in good states then continue if status in ['FINISHED', 'STARTED']: continue # We have a compose that either failed or had missing artifacts # create a new issue. title = msg['msg']['compose_id'] + ' ' + status logfileurl = msg['msg'][ 'location'] + '/../logs/global/pungi.global.log' logger.info("%s\t%s" % (title, logfileurl)) # variable to hold description for issue content = "[pungi.global.log](%s)\n\n" % logfileurl # If we fail to get the log file contents then we'll just # best effort put a message in the issue. try: lines = requests.get(logfileurl).text.splitlines() except: logger.info( "Failed to retrieve log contents from server.. skipping analysis" ) content += "Failed to retrieve log contents from server.. skipping analysis" lines = [] pass for x in range(1, len(lines)): line = lines[x - 1][20:] # trim date off log lines nextline = lines[x][20:] # trim date off log lines # If this is a [FAIL] line then we take it and the # next line and add them in markdown format. Also grab # the taskid if we can and print a hyperlink to koji if re.search('\[FAIL\]', line): content += get_supporting_text(nextline) content += "```\n%s\n%s\n```\n\n" % (line, nextline) # If this is the Compose run failed line, then add it # to the description too if re.search('.*Compose run failed.*', line): content += ("- Compose run failed because: %s\n" % get_supporting_text(line)) content += "```\n%s\n```\n" % (line) logger.debug(content) # pull only part of the compose ID for the tag to set tag = re.search('(.*)-\d{8}', msg['msg']['compose_id']).group(1) #TODO figure out how to set tag on an issue if token: pg.create_issue(title=title, content=content)