From bdfdc426241c4388d01455f1d5b53ebe65935a01 Mon Sep 17 00:00:00 2001 From: Andy Feller Date: Tue, 5 Dec 2023 08:33:00 -0500 Subject: [PATCH 1/2] Revert "Update triage.yml" This reverts commit 3be9a0ed8519553b877398e3414af3ab02aeac82. --- .github/workflows/triage.yml | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/.github/workflows/triage.yml b/.github/workflows/triage.yml index 55c605090..71fc5426d 100644 --- a/.github/workflows/triage.yml +++ b/.github/workflows/triage.yml @@ -1,9 +1,12 @@ name: Discussion Triage -run-name: ${{ github.event.issue.title }} +run-name: ${{ github.event_name == 'issues' && github.event.issue.title || github.event.pull_request.title }} on: issues: types: - labeled + pull_request: + types: + - labeled env: TARGET_REPO: github/cli jobs: @@ -34,3 +37,31 @@ jobs: > $BODY EOF + + pull_request: + runs-on: ubuntu-latest + if: github.event_name == 'pull_request' && github.event.action == 'labeled' && github.event.label.name == 'discuss' + steps: + - name: Create discuss issue based on source pull request + env: + BODY: ${{ github.event.pull_request.body }} + CREATED: ${{ github.event.pull_request.created_at }} + GH_TOKEN: ${{ secrets.CLI_DISCUSSION_TRIAGE_TOKEN }} + LINK: ${{ github.repository }}#${{ github.event.pull_request.number }} + TITLE: ${{ github.event.pull_request.title }} + TRIGGERED_BY: ${{ github.triggering_actor }} + run: | + # Markdown quote source body by replacing newlines for newlines and markdown quoting + BODY="${BODY//$'\n'/$'\n'> }" + + # Create discuss issue using dynamically constructed body within heredoc + cat << EOF | gh issue create --title "Triage PR \"$TITLE\"" --body-file - --repo "$TARGET_REPO" --label discuss + **Title:** $TITLE + **Pull request:** $LINK + **Created:** $CREATED + **Triggered by:** @$TRIGGERED_BY + + --- + + > $BODY + EOF From 8302a293d0ead27ebae3bdfaa375442e91cc3397 Mon Sep 17 00:00:00 2001 From: Andy Feller Date: Tue, 5 Dec 2023 08:46:45 -0500 Subject: [PATCH 2/2] Fix triage workflow, restore PR support This commit reverts the triage workflow to restore the previous PR support using the `pull_request_target`, which is more secure as it doesn't allow fork repositories to change the workflow before it runs. Additionally, this fixes an issue currently causing the workflow to break as cli/cli uses the `discuss` label but github/cli uses the `triage` label. --- .github/workflows/triage.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/triage.yml b/.github/workflows/triage.yml index 71fc5426d..6cd9d981d 100644 --- a/.github/workflows/triage.yml +++ b/.github/workflows/triage.yml @@ -4,7 +4,7 @@ on: issues: types: - labeled - pull_request: + pull_request_target: types: - labeled env: @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest if: github.event_name == 'issues' && github.event.action == 'labeled' && github.event.label.name == 'discuss' steps: - - name: Create discuss issue based on source issue + - name: Create issue based on source issue env: BODY: ${{ github.event.issue.body }} CREATED: ${{ github.event.issue.created_at }} @@ -26,8 +26,8 @@ jobs: # Markdown quote source body by replacing newlines for newlines and markdown quoting BODY="${BODY//$'\n'/$'\n'> }" - # Create discuss issue using dynamically constructed body within heredoc - cat << EOF | gh issue create --title "Triage issue \"$TITLE\"" --body-file - --repo "$TARGET_REPO" --label discuss + # Create issue using dynamically constructed body within heredoc + cat << EOF | gh issue create --title "Triage issue \"$TITLE\"" --body-file - --repo "$TARGET_REPO" --label triage **Title:** $TITLE **Issue:** $LINK **Created:** $CREATED @@ -40,9 +40,9 @@ jobs: pull_request: runs-on: ubuntu-latest - if: github.event_name == 'pull_request' && github.event.action == 'labeled' && github.event.label.name == 'discuss' + if: github.event_name == 'pull_request_target' && github.event.action == 'labeled' && github.event.label.name == 'discuss' steps: - - name: Create discuss issue based on source pull request + - name: Create issue based on source pull request env: BODY: ${{ github.event.pull_request.body }} CREATED: ${{ github.event.pull_request.created_at }} @@ -54,8 +54,8 @@ jobs: # Markdown quote source body by replacing newlines for newlines and markdown quoting BODY="${BODY//$'\n'/$'\n'> }" - # Create discuss issue using dynamically constructed body within heredoc - cat << EOF | gh issue create --title "Triage PR \"$TITLE\"" --body-file - --repo "$TARGET_REPO" --label discuss + # Create issue using dynamically constructed body within heredoc + cat << EOF | gh issue create --title "Triage PR \"$TITLE\"" --body-file - --repo "$TARGET_REPO" --label triage **Title:** $TITLE **Pull request:** $LINK **Created:** $CREATED