From 7203187d4430286634503eca9b806f01d6eb1931 Mon Sep 17 00:00:00 2001 From: WordPressFan Date: Wed, 31 Jan 2024 15:40:14 +0200 Subject: [PATCH 1/6] [WIP] start testing the package and adding comment --- .github/workflows/pull-request-comments.yml | 32 +++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/.github/workflows/pull-request-comments.yml b/.github/workflows/pull-request-comments.yml index df276270f1396..aa887ce05128c 100644 --- a/.github/workflows/pull-request-comments.yml +++ b/.github/workflows/pull-request-comments.yml @@ -163,3 +163,35 @@ jobs: `; github.rest.issues.createComment( commentInfo ); + + + - name: Comment on a PR when no Trac ticket is included + uses: JJ/github-pr-contains-action@releases/v11 + with: + github-token: ${{github.token}} + bodyDoesNotContain: "core\.trac\.wordpress\.org\/ticket\/\d+" + script: | + const fs = require( 'fs' ); + const issue_number = Number( fs.readFileSync( './NR' ) ); + + // Comments are only added after the first successful build. Check for the presence of a comment and bail early. + const commentInfo = { + owner: context.repo.owner, + repo: context.repo.repo, + issue_number, + }; + + const comments = ( await github.rest.issues.listComments( commentInfo ) ).data; + + for ( const currentComment of comments ) { + if ( currentComment.user.type === 'Bot' && currentComment.body.includes( 'Test Comment from ahmed' ) ) { + return; + } + }; + + // No comment was found. Create one. + commentInfo.body = `## Test Comment from ahmed + Hi Hi Hi + `; + + github.rest.issues.createComment( commentInfo ); From ca6768d6463fdedd5c663846da8f26a97d318716 Mon Sep 17 00:00:00 2001 From: WordPressFan Date: Wed, 31 Jan 2024 15:49:24 +0200 Subject: [PATCH 2/6] adjust the workflow --- .github/workflows/pull-request-comments.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pull-request-comments.yml b/.github/workflows/pull-request-comments.yml index aa887ce05128c..abe524b1dfd50 100644 --- a/.github/workflows/pull-request-comments.yml +++ b/.github/workflows/pull-request-comments.yml @@ -165,7 +165,19 @@ jobs: github.rest.issues.createComment( commentInfo ); - - name: Comment on a PR when no Trac ticket is included + + no-trac-url-included: + name: Comment on a pull request when no Trac ticket is included + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + if: > + github.repository == 'wp-media/wordpress-develop' && + github.event.workflow_run.event == 'pull_request' && + github.event.workflow_run.conclusion == 'success' + steps: + - name: Add the comment uses: JJ/github-pr-contains-action@releases/v11 with: github-token: ${{github.token}} From 89a0f73f3efc30ea00121e9204ea2523469feab0 Mon Sep 17 00:00:00 2001 From: WordPressFan Date: Wed, 31 Jan 2024 15:50:20 +0200 Subject: [PATCH 3/6] add synchronize for testing --- .github/workflows/pull-request-comments.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-request-comments.yml b/.github/workflows/pull-request-comments.yml index abe524b1dfd50..a4fce94499544 100644 --- a/.github/workflows/pull-request-comments.yml +++ b/.github/workflows/pull-request-comments.yml @@ -3,7 +3,7 @@ name: Pull Request Comments on: pull_request_target: - types: [ 'opened' ] + types: [ 'opened', 'synchronize' ] workflow_run: workflows: [ 'Test Build Processes' ] types: From ae2d5e192be83ce738a95866f21ca8975a54ae85 Mon Sep 17 00:00:00 2001 From: WordPressFan Date: Wed, 31 Jan 2024 15:56:11 +0200 Subject: [PATCH 4/6] add synchronize for testing in pull_request --- .github/workflows/pull-request-comments.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pull-request-comments.yml b/.github/workflows/pull-request-comments.yml index a4fce94499544..6a0e6c82d0ac8 100644 --- a/.github/workflows/pull-request-comments.yml +++ b/.github/workflows/pull-request-comments.yml @@ -2,8 +2,10 @@ name: Pull Request Comments on: - pull_request_target: + pull_request: types: [ 'opened', 'synchronize' ] + pull_request_target: + types: [ 'opened' ] workflow_run: workflows: [ 'Test Build Processes' ] types: From 22968867742a8f6dc412a2d7b244cafb2e793509 Mon Sep 17 00:00:00 2001 From: WordPressFan Date: Wed, 31 Jan 2024 16:02:32 +0200 Subject: [PATCH 5/6] test another way --- .github/workflows/pull-request-comments.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pull-request-comments.yml b/.github/workflows/pull-request-comments.yml index 6a0e6c82d0ac8..12cbd99409464 100644 --- a/.github/workflows/pull-request-comments.yml +++ b/.github/workflows/pull-request-comments.yml @@ -3,7 +3,8 @@ name: Pull Request Comments on: pull_request: - types: [ 'opened', 'synchronize' ] + branches: + - trunk pull_request_target: types: [ 'opened' ] workflow_run: From db2bd7135bd47df902d23ed3350940c9acb0ae91 Mon Sep 17 00:00:00 2001 From: WordPressFan Date: Wed, 31 Jan 2024 16:05:26 +0200 Subject: [PATCH 6/6] remove the condition completely --- .github/workflows/pull-request-comments.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/pull-request-comments.yml b/.github/workflows/pull-request-comments.yml index 12cbd99409464..6f549fb277a14 100644 --- a/.github/workflows/pull-request-comments.yml +++ b/.github/workflows/pull-request-comments.yml @@ -175,10 +175,6 @@ jobs: permissions: issues: write pull-requests: write - if: > - github.repository == 'wp-media/wordpress-develop' && - github.event.workflow_run.event == 'pull_request' && - github.event.workflow_run.conclusion == 'success' steps: - name: Add the comment uses: JJ/github-pr-contains-action@releases/v11