1*a2adebf4STom Stellard#!/usr/bin/env python3 2*a2adebf4STom Stellard# 3*a2adebf4STom Stellard# ======- github-automation - LLVM GitHub Automation Routines--*- python -*--==# 4*a2adebf4STom Stellard# 5*a2adebf4STom Stellard# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 6*a2adebf4STom Stellard# See https://llvm.org/LICENSE.txt for license information. 7*a2adebf4STom Stellard# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 8*a2adebf4STom Stellard# 9*a2adebf4STom Stellard# ==-------------------------------------------------------------------------==# 10*a2adebf4STom Stellard 11*a2adebf4STom Stellardimport argparse 12*a2adebf4STom Stellardimport github 13*a2adebf4STom Stellardimport os 14*a2adebf4STom Stellard 15*a2adebf4STom Stellardclass IssueSubscriber: 16*a2adebf4STom Stellard 17*a2adebf4STom Stellard @property 18*a2adebf4STom Stellard def team_name(self) -> str: 19*a2adebf4STom Stellard return self._team_name 20*a2adebf4STom Stellard 21*a2adebf4STom Stellard def __init__(self, token:str, repo:str, issue_number:int, label_name:str): 22*a2adebf4STom Stellard self.repo = github.Github(token).get_repo(repo) 23*a2adebf4STom Stellard self.org = github.Github(token).get_organization(self.repo.organization.login) 24*a2adebf4STom Stellard self.issue = self.repo.get_issue(issue_number) 25*a2adebf4STom Stellard self._team_name = 'issue-subscribers-{}'.format(label_name).lower() 26*a2adebf4STom Stellard 27*a2adebf4STom Stellard def run(self) -> bool: 28*a2adebf4STom Stellard for team in self.org.get_teams(): 29*a2adebf4STom Stellard if self.team_name != team.name.lower(): 30*a2adebf4STom Stellard continue 31*a2adebf4STom Stellard comment = '@llvm/{}'.format(team.slug) 32*a2adebf4STom Stellard self.issue.create_comment(comment) 33*a2adebf4STom Stellard return True 34*a2adebf4STom Stellard return False 35*a2adebf4STom Stellard 36*a2adebf4STom Stellard 37*a2adebf4STom Stellardparser = argparse.ArgumentParser() 38*a2adebf4STom Stellardparser.add_argument('--token', type=str, required=True) 39*a2adebf4STom Stellardparser.add_argument('--repo', type=str, default=os.getenv('GITHUB_REPOSITORY', 'llvm/llvm-project')) 40*a2adebf4STom Stellardsubparsers = parser.add_subparsers(dest='command') 41*a2adebf4STom Stellard 42*a2adebf4STom Stellardissue_subscriber_parser = subparsers.add_parser('issue-subscriber') 43*a2adebf4STom Stellardissue_subscriber_parser.add_argument('--label-name', type=str, required=True) 44*a2adebf4STom Stellardissue_subscriber_parser.add_argument('--issue-number', type=int, required=True) 45*a2adebf4STom Stellard 46*a2adebf4STom Stellardargs = parser.parse_args() 47*a2adebf4STom Stellard 48*a2adebf4STom Stellardif args.command == 'issue-subscriber': 49*a2adebf4STom Stellard issue_subscriber = IssueSubscriber(args.token, args.repo, args.issue_number, args.label_name) 50*a2adebf4STom Stellard issue_subscriber.run() 51