Skip to content

Commit

Permalink
Fix up for merging
Browse files Browse the repository at this point in the history
  • Loading branch information
driazati committed Aug 3, 2022
1 parent 08bc800 commit 38ec51a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,12 @@ concurrency:

jobs:
MacOS:
if: ${{ github.repository == 'driazati/tvm' }}
runs-on: ubuntu-latest
if: ${{ github.repository == 'apache/tvm' }}
runs-on: macOS-latest
steps:
- uses: actions/checkout@v2
with:
submodules: 'recursive'
- name: fail
run: |
exit 1
- name: Set up environment
uses: ./.github/actions/setup
- name: Conda Build
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tvmbot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ jobs:
issues: write
pull-requests: write
statuses: write
if: ${{ github.event.issue.pull_request && github.repository == 'driazati/tvm' }}
if: ${{ github.event.issue.pull_request && github.repository == 'apache/tvm' }}
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Run tvm-bot
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_API_TOKEN: ${{ secrets.GH_API_TOKEN }}
GH_ACTIONS_TOKEN: ${{ secrets.GH_ACTIONS_TOKEN }}
TVM_BOT_JENKINS_TOKEN: ${{ secrets.TVM_BOT_JENKINS_TOKEN }}
PR_NUMBER: ${{ github.event.issue.number }}
ISSUE_COMMENT: ${{ toJson(github.event.comment) }}
Expand Down
41 changes: 34 additions & 7 deletions tests/scripts/github_tvmbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

EXPECTED_JOBS = ["tvm-ci/pr-head"]
TVM_BOT_JENKINS_TOKEN = os.environ["TVM_BOT_JENKINS_TOKEN"]
GH_API_TOKEN = os.environ["GH_API_TOKEN"]
GH_ACTIONS_TOKEN = os.environ["GH_ACTIONS_TOKEN"]
JENKINS_URL = "https://ci.tlcpack.ai/"
THANKS_MESSAGE = r"(\s*)Thanks for contributing to TVM! Please refer to guideline https://tvm.apache.org/docs/contribute/ for useful information and tips. After the pull request is submitted, please request code reviews from \[Reviewers\]\(https://github.com/apache/incubator-tvm/blob/master/CONTRIBUTORS.md#reviewers\) by them in the pull request thread.(\s*)"

Expand All @@ -58,6 +58,18 @@ def to_json_str(obj: Any) -> str:
}
"""

MENTIONABLE_QUERY = """
query ($owner: String!, $name: String!, $user: String!) {
repository(owner: $owner, name: $name) {
mentionableUsers(query: $user, first: 1) {
nodes {
login
}
}
}
}
"""


PR_QUERY = """
query ($owner: String!, $name: String!, $number: Int!) {
Expand Down Expand Up @@ -328,15 +340,21 @@ def search_collaborator(self, user: str) -> List[Dict[str, Any]]:
"""
Query GitHub for collaborators matching 'user'
"""
return self.search_users(user, COLLABORATORS_QUERY)["collaborators"]["nodes"]

def search_users(self, user: str, query: str) -> List[Dict[str, Any]]:
return self.github.graphql(
query=COLLABORATORS_QUERY,
query=query,
variables={
"owner": self.owner,
"name": self.repo_name,
"user": user,
},
)["data"]["repository"]["collaborators"]["nodes"]

def search_mentionable_users(self, user: str) -> List[Dict[str, Any]]:
return self.search_users(user, MENTIONABLE_QUERY)["mentionableUsers"]["nodes"]

def comment(self, text: str) -> None:
"""
Leave the comment 'text' on this PR
Expand Down Expand Up @@ -513,7 +531,7 @@ def rerun_github_actions(self) -> None:

logging.info(f"Rerunning GitHub Actions jobs with IDs: {job_ids}")
actions_github = GitHubRepo(
user=self.github.user, repo=self.github.repo, token=GH_API_TOKEN
user=self.github.user, repo=self.github.repo, token=GH_ACTIONS_TOKEN
)
for job_id in job_ids:
try:
Expand Down Expand Up @@ -558,12 +576,21 @@ def check_collaborator(pr, triggering_comment, args):
return len(collaborators) > 0


def check_anyone(pr, triggering_comment, args):
return True
def check_mentionable_users(pr, triggering_comment, args):
logging.info("Checking mentionable users")
# Get the list of collaborators for the repo filtered by the comment
# author
if args.testing_mentionable_users_json:
mentionable_users = json.loads(args.testing_mentionable_users_json)
else:
mentionable_users = pr.search_mentionable_users(triggering_comment["user"]["login"])
logging.info(f"Found mentionable_users: {mentionable_users}")

return len(mentionable_users) > 0


AUTH_CHECKS = {
"anyone": check_anyone,
"metionable_users": check_mentionable_users,
"collaborators": check_collaborator,
"author": check_author,
}
Expand Down Expand Up @@ -607,7 +634,7 @@ class Rerun:
"run ci",
]

auth = [AUTH_CHECKS["anyone"]]
auth = [AUTH_CHECKS["metionable_users"]]

@staticmethod
def run(pr: PR):
Expand Down

0 comments on commit 38ec51a

Please sign in to comment.