diff --git a/.github/helper_scripts/post_check_results.py b/.github/helper_scripts/post_check_results.py index cbf7b32..0e39b4c 100644 --- a/.github/helper_scripts/post_check_results.py +++ b/.github/helper_scripts/post_check_results.py @@ -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([ diff --git a/.github/helper_scripts/pr_close_comment.py b/.github/helper_scripts/pr_close_comment.py index 0f45ac4..f04acc2 100644 --- a/.github/helper_scripts/pr_close_comment.py +++ b/.github/helper_scripts/pr_close_comment.py @@ -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 diff --git a/.github/workflows/check-issue.yml b/.github/workflows/check-issue.yml new file mode 100644 index 0000000..5e3240d --- /dev/null +++ b/.github/workflows/check-issue.yml @@ -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." diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index ca9ce72..5e0fef6 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -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' || '' }}