def apply(self, g, o: github.Issue.Issue): days_since_created = None days_since_updated = None now = datetime.now() if o.state == 'closed': return if o.created_at is not None: days_since_created = (now - o.created_at).days else: return if days_since_created < self.stale_days: return if o.updated_at is not None: days_since_updated = (now - o.updated_at).days else: return if days_since_updated < self.stale_days: return if HasLabel(o, self.ignore_lifecycle_label) or HasLabel( o, self.beginner_friendly_label): return if HasLabel(o, 'to-be-closed'): o.create_comment( "This issue is tagged as 'to-be-closed' and hasn't been updated " + " in {} days, ".format(days_since_updated) + "so we are closing it. You can always reopen this issue if needed." ) o.edit(state='closed') elif HasLabel(o, 'stale'): o.create_comment( "This issue is tagged as 'stale' and hasn't been updated " + " in {} days, ".format(days_since_updated) + "so we are tagging it as 'to-be-closed'. It will be closed " + "in {} days unless updates are made. ".format(self.stale_days) + "If you want to remove this label, comment:\n\n" + "> @spinnakerbot remove-label to-be-closed") AddLabel(g, o, 'to-be-closed') else: o.create_comment( "This issue hasn't been updated in {} days, ".format( days_since_updated) + "so we are tagging it as 'stale'. If you want to remove this label, comment:\n\n" + "> @spinnakerbot remove-label stale") AddLabel(g, o, 'stale')
def apply(self, g, o): if o.created_at is None: return now = datetime.now() days_since_created = (now - o.created_at).days if days_since_created < self.stale_days: return if HasLabel(o, 'stale'): return repo = IssueRepo(o) newest_date = o.created_at for e in o.get_events(): if e.created_at > newest_date: newest_date = e.created_at delta = now - newest_date if delta.days >= self.stale_days: self.logging.info( "Tagging {} as stale after {} days since last activity".format( o.url, delta.days)) AddLabel(g, o, 'stale')
def handle(self, g, event): # avoid fetching until needed issue = None for command in GetCommands( event.payload.get('comment', {}).get('body')): if command[0] != 'add-label': continue if issue is None: issue = GetIssue(g, event) for label in command[1:]: AddLabel(g, issue, label, create=False)
def do_cherry_pick(self, g, pull_request, repo, commit, release): if not pull_request.is_merged: pull_request.create_issue_comment(not_merged) try: p = g.cherry_pick(repo=repo, release=release, commit=commit) AddLabel(g, p, cherry_pick_label) pull_request.create_issue_comment( "Cherry pick successful: #{}".format(p.number)) except RuntimeError as e: pull_request.create_issue_comment("Cherry pick failed: {}".format( str(e)))
def apply(self, g, o): now = datetime.now() delta = now - o.created_at # exit early to avoid listing all events if delta.days < self.stale_days: return if HasLabel(o, 'stale'): return repo = IssueRepo(o) newest_date = o.created_at for e in o.get_events(): if e.created_at > newest_date: newest_date = e.created_at delta = now - newest_date if delta.days >= self.stale_days: self.logging.info( "Tagging {} as stale after {} days since last activity".format( o.url, delta.days)) AddLabel(g, o, 'stale')
def target_release(self, g, pull_request, release_branch): release_name = '.'.join([str(v) for v in release_branch]) label = 'target-release/{}'.format(release_name) AddLabel(g, pull_request, label) return release_name