Skip to content
Open
9 changes: 6 additions & 3 deletions .github/helper_scripts/post_check_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ def CollectResults():
return rows, failed

def PostResults(repo, run_id, rows, failed):
run_url = f"https://github.com/{repo}/actions/runs/{run_id}"
table = "\n".join(["| Check | Result | Time |", "|-------|--------|------|", *rows])
body = f"**Check Results** ([run details]({run_url}))\n\n{table}"
run_url = f"https://github.com/{repo}/actions/runs/{run_id}"
comment_author = os.environ.get("COMMENT_AUTHOR", "")
comment_url = os.environ.get("COMMENT_URL", "")
table = "\n".join(["| Check | Result | Time |", "|-------|--------|------|", *rows])
attribution = f"Triggered by @{comment_author} on [this comment]({comment_url})\n\n" if comment_author else ""
body = f"{attribution}**Check Results** ([run details]({run_url}))\n\n{table}"
pr_num = os.environ["PR_NUMBER"]
pr_sha = os.environ["PR_SHA"]
subprocess.run([
Expand Down
10 changes: 7 additions & 3 deletions .github/helper_scripts/pr_close_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,22 @@ def Main():
repo = Github(auth=Auth.Token(github_token)).get_repo(repo_name)
pr = repo.get_pull(pr_number)

issue_comment_url = PostCommentOnIssueThread(repo, branch_name, last_commit_sha)
merge_commit_sha = pr.merge_commit_sha
issue_comment_url = PostCommentOnIssueThread(repo, branch_name, last_commit_sha, merge_commit_sha)
PostCommentOnPRThread(pr, user_closing_pr, issue_comment_url)
return 0


def PostCommentOnIssueThread(repo, branch_name, last_commit_sha):
def PostCommentOnIssueThread(repo, branch_name, last_commit_sha, merge_commit_sha):
issue_match = re.match(r"^(\d+)", branch_name)
if not issue_match:
return None

issue_number = int(issue_match.group(1))
issue_body = ISSUE_TEMPLATE.read_text() + f"\n\nLast commit in issue branch: {last_commit_sha}"
issue_body = ISSUE_TEMPLATE.read_text()
issue_body += f"\n\nLast commit in issue branch: {last_commit_sha}"
if merge_commit_sha:
issue_body += f"\n\nMerge commit: {merge_commit_sha}"

comment = repo.get_issue(issue_number).create_comment(issue_body)
return comment.html_url
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/check-issue.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Check issue/ is empty

on:
pull_request:
branches: [main, master]
types: [opened]
push:
branches:
- "**"
issue_comment:
types: [created]

jobs:
check-issue:
if: |
github.event_name == 'pull_request' ||
(github.event_name == 'push' && (contains(github.event.head_commit.message, '[run-actions-all]') || contains(github.event.head_commit.message, '[run-actions-issue]'))) ||
(github.event_name == 'issue_comment' && github.event.issue.pull_request && (contains(github.event.comment.body, '/run-actions-issue') || contains(github.event.comment.body, '/run-actions-all')))
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'issue_comment' && format('refs/pull/{0}/head', github.event.issue.number) || github.sha }}
- name: Fail if issue/ is non-empty
run: |
if [ -d "issue" ] && [ -n "$(ls -A issue/)" ]; then
echo "issue/ is not empty. Please delete its contents before merging."
exit 1
fi
echo "issue/ is empty or does not exist."
2 changes: 2 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ jobs:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.issue.number }}
PR_SHA: ${{ env.PR_SHA }}
COMMENT_AUTHOR: ${{ github.event.comment.user.login }}
COMMENT_URL: ${{ github.event.comment.html_url }}
run: |
python .github/helper_scripts/post_check_results.py \
${{ contains(github.event.comment.body, '--post') && '--post' || '' }}
1 change: 1 addition & 0 deletions issue/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
placehold