[llvm] a2adebf - workflows: Make issue-subscriber more robust for labels with special characters
Tom Stellard via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 14 22:06:02 PST 2022
Author: Tom Stellard
Date: 2022-01-14T22:04:54-08:00
New Revision: a2adebf409ce2559618720039f19d61281b182bc
URL: https://github.com/llvm/llvm-project/commit/a2adebf409ce2559618720039f19d61281b182bc
DIFF: https://github.com/llvm/llvm-project/commit/a2adebf409ce2559618720039f19d61281b182bc.diff
LOG: workflows: Make issue-subscriber more robust for labels with special characters
Also, replace the existing actionscript implementation with a python
script that can be run outside of GitHub Actions. The intention is
that going forward, all github action functionality would be implemented
in this script.
Reviewed By: kwk
Differential Revision: https://reviews.llvm.org/D116762
Added:
llvm/utils/git/github-automation.py
Modified:
.github/workflows/issue-subscriber.yml
Removed:
################################################################################
diff --git a/.github/workflows/issue-subscriber.yml b/.github/workflows/issue-subscriber.yml
index 51c55fa362add..af904c0f26bf8 100644
--- a/.github/workflows/issue-subscriber.yml
+++ b/.github/workflows/issue-subscriber.yml
@@ -10,26 +10,16 @@ jobs:
runs-on: ubuntu-latest
if: github.repository == 'llvm/llvm-project'
steps:
+ - name: Setup Automation Script
+ run: |
+ curl -O -L https://raw.githubusercontent.com/$GITHUB_REPOSITORY/$GITHUB_SHA/llvm/utils/git/github-automation.py
+ chmod a+x github-automation.py
+ pip install PyGithub
+
- name: Update watchers
- uses: actions/github-script at v5
- with:
- github-token: ${{ secrets.ISSUE_MENTION_SECRET }}
- script: |
- const teamname = "issue-subscribers-" + context.payload.label.name.replace(/ /g, "-").replace(":","-").replace("/","-");
- const comment = "@llvm/" + teamname;
- try {
- // This will throw an exception if the team does not exist and no
- // comment will be created.
- team = await github.rest.teams.getByName({
- org: context.repo.owner,
- team_slug: teamname
- });
- github.rest.issues.createComment({
- issue_number: context.issue.number,
- owner: context.repo.owner,
- repo: context.repo.repo,
- body: comment
- });
- } catch (e){
- console.log(e);
- }
+ run: |
+ ./github-automation.py \
+ --token ${{ secrets.ISSUE_SUBSCRIBER_TOKEN }} \
+ issue-subscriber \
+ --issue-number ${{ github.event.issue.number }} \
+ --label-name ${{ github.event.label.name }}
diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
new file mode 100755
index 0000000000000..9caa8588ddd76
--- /dev/null
+++ b/llvm/utils/git/github-automation.py
@@ -0,0 +1,50 @@
+#!/usr/bin/env python3
+#
+# ======- github-automation - LLVM GitHub Automation Routines--*- python -*--==#
+#
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+#
+# ==-------------------------------------------------------------------------==#
+
+import argparse
+import github
+import os
+
+class IssueSubscriber:
+
+ @property
+ def team_name(self) -> str:
+ return self._team_name
+
+ def __init__(self, token:str, repo:str, issue_number:int, label_name:str):
+ self.repo = github.Github(token).get_repo(repo)
+ self.org = github.Github(token).get_organization(self.repo.organization.login)
+ self.issue = self.repo.get_issue(issue_number)
+ self._team_name = 'issue-subscribers-{}'.format(label_name).lower()
+
+ def run(self) -> bool:
+ for team in self.org.get_teams():
+ if self.team_name != team.name.lower():
+ continue
+ comment = '@llvm/{}'.format(team.slug)
+ self.issue.create_comment(comment)
+ return True
+ return False
+
+
+parser = argparse.ArgumentParser()
+parser.add_argument('--token', type=str, required=True)
+parser.add_argument('--repo', type=str, default=os.getenv('GITHUB_REPOSITORY', 'llvm/llvm-project'))
+subparsers = parser.add_subparsers(dest='command')
+
+issue_subscriber_parser = subparsers.add_parser('issue-subscriber')
+issue_subscriber_parser.add_argument('--label-name', type=str, required=True)
+issue_subscriber_parser.add_argument('--issue-number', type=int, required=True)
+
+args = parser.parse_args()
+
+if args.command == 'issue-subscriber':
+ issue_subscriber = IssueSubscriber(args.token, args.repo, args.issue_number, args.label_name)
+ issue_subscriber.run()
More information about the llvm-commits
mailing list