From 15dc2635a3a41b4cdac0c6bc5bdc48201f118814 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Fri, 31 May 2024 16:03:18 +0200 Subject: [PATCH 01/12] Add step to close previous community metrics issue --- .github/workflows/community_metrics.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/community_metrics.yml b/.github/workflows/community_metrics.yml index 720799ab124..2c7760376b1 100644 --- a/.github/workflows/community_metrics.yml +++ b/.github/workflows/community_metrics.yml @@ -70,7 +70,18 @@ jobs: shell: pwsh run: | Get-Content ./community_metrics.md >> $env:GITHUB_STEP_SUMMARY - + + - name: Close Previous Issue + shell: pwsh + run: | + $issues = gh issue list --label "community metrics" --state open --json number --jq '.[].number' + foreach ($issue in $issues) + { + gh issue close $issue --comment 'Closing this issue as newer community metrics are available.' + } + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Create Issue # v5.0.0 uses: peter-evans/create-issue-from-file@24452a72d85239eacf1468b0f1982a9f3fec4c94 From 682617e3cef325fe88115cf5203a1d5eb0bed556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Fri, 31 May 2024 16:03:51 +0200 Subject: [PATCH 02/12] Test run --- .github/workflows/community_metrics.yml | 72 +------------------------ 1 file changed, 2 insertions(+), 70 deletions(-) diff --git a/.github/workflows/community_metrics.yml b/.github/workflows/community_metrics.yml index 2c7760376b1..737e546a025 100644 --- a/.github/workflows/community_metrics.yml +++ b/.github/workflows/community_metrics.yml @@ -1,10 +1,7 @@ name: Community Metrics on: - workflow_dispatch: - schedule: - # Run on the first day of every month at 2:19 AM UTC. - - cron: '19 2 1 * *' - + pull_request: + permissions: issues: write pull-requests: read @@ -14,63 +11,6 @@ jobs: name: Generate Community Metrics runs-on: ubuntu-latest steps: - - name: Get Dates For Last Month - shell: pwsh - run: | - # Calculate the first day of the previous month. - $firstDay = (Get-Date).AddMonths(-1).ToString("yyyy-MM-01") - - # Calculate the last day of the previous month. - $lastDay = (Get-Date $firstDay).AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd") - - # Set an environment variable with the date range. - Write-Output "$firstDay..$lastDay" - Write-Output "LAST_MONTH=$firstDay..$lastDay" >> $env:GITHUB_ENV - - - name: Compute Issue Metrics - uses: github/issue-metrics@v3 - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SEARCH_QUERY: 'repo:OrchardCMS/OrchardCore is:issue created:${{ env.LAST_MONTH }} -reason:"not planned" -label:"community metrics"' - HIDE_TIME_TO_ANSWER: true - - - name: Rename Issue Metrics File - shell: pwsh - run: | - # Renaming the file wouldn't work since other scripts will be denied access to it for some reason. - Add-Content -Path ./community_metrics.md -Value (Get-Content -Path ./issue_metrics.md -Raw) - - - name: Compute Pull Request Metrics - uses: github/issue-metrics@v3 - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SEARCH_QUERY: 'repo:OrchardCMS/OrchardCore is:pr created:${{ env.LAST_MONTH }} -label:dontmerge -label:notready -is:draft' - HIDE_TIME_TO_ANSWER: true - - - name: Concatenate Issue and Pull Request Metrics - shell: pwsh - run: | - $content = (Get-Content -Path ./issue_metrics.md -Raw) -replace '# Issue Metrics', '# Pull Request Metrics' - Add-Content -Path ./community_metrics.md -Value ([Environment]::NewLine + $content) - - - name: Compute Q&A Discussion Request Metrics - uses: github/issue-metrics@v3 - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SEARCH_QUERY: 'repo:OrchardCMS/OrchardCore type:discussions created:${{ env.LAST_MONTH }} category:Q&A' - HIDE_TIME_TO_CLOSE: true - - - name: Concatenate Issue/PR and Discussion Metrics - shell: pwsh - run: | - $content = (Get-Content -Path ./issue_metrics.md -Raw) -replace '# Issue Metrics', '# Discussion Metrics' - Add-Content -Path ./community_metrics.md -Value ([Environment]::NewLine + $content) - - - name: Display Issue Metrics in Summary - shell: pwsh - run: | - Get-Content ./community_metrics.md >> $env:GITHUB_STEP_SUMMARY - - name: Close Previous Issue shell: pwsh run: | @@ -82,11 +22,3 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Create Issue - # v5.0.0 - uses: peter-evans/create-issue-from-file@24452a72d85239eacf1468b0f1982a9f3fec4c94 - with: - title: Monthly community metrics report for ${{ env.LAST_MONTH }} - token: ${{ secrets.GITHUB_TOKEN }} - content-filepath: ./community_metrics.md - labels: community metrics From f964be8d512620fbd9890ed5052b29c2eabc1b73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Fri, 31 May 2024 16:11:29 +0200 Subject: [PATCH 03/12] Adding repo reference --- .github/workflows/community_metrics.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/community_metrics.yml b/.github/workflows/community_metrics.yml index 737e546a025..70c9ebafb1f 100644 --- a/.github/workflows/community_metrics.yml +++ b/.github/workflows/community_metrics.yml @@ -14,7 +14,7 @@ jobs: - name: Close Previous Issue shell: pwsh run: | - $issues = gh issue list --label "community metrics" --state open --json number --jq '.[].number' + $issues = gh issue list --repo '${{ github.action_repository }}' --label 'community metrics' --state open --json number --jq '.[].number' foreach ($issue in $issues) { gh issue close $issue --comment 'Closing this issue as newer community metrics are available.' From cb7c6385aa71005de6393f3a0041898b1d3f8a9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Fri, 31 May 2024 16:13:14 +0200 Subject: [PATCH 04/12] Fixing repo reference --- .github/workflows/community_metrics.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/community_metrics.yml b/.github/workflows/community_metrics.yml index 70c9ebafb1f..28e2f9d9da6 100644 --- a/.github/workflows/community_metrics.yml +++ b/.github/workflows/community_metrics.yml @@ -14,7 +14,7 @@ jobs: - name: Close Previous Issue shell: pwsh run: | - $issues = gh issue list --repo '${{ github.action_repository }}' --label 'community metrics' --state open --json number --jq '.[].number' + $issues = gh issue list --repo '${{ github.repository }}' --label 'community metrics' --state open --json number --jq '.[].number' foreach ($issue in $issues) { gh issue close $issue --comment 'Closing this issue as newer community metrics are available.' From 0898419bed323d84cb9079e1fa063867ccaad14f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Fri, 31 May 2024 16:18:28 +0200 Subject: [PATCH 05/12] Debug output --- .github/workflows/community_metrics.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/community_metrics.yml b/.github/workflows/community_metrics.yml index 28e2f9d9da6..bd56e6974e8 100644 --- a/.github/workflows/community_metrics.yml +++ b/.github/workflows/community_metrics.yml @@ -17,7 +17,7 @@ jobs: $issues = gh issue list --repo '${{ github.repository }}' --label 'community metrics' --state open --json number --jq '.[].number' foreach ($issue in $issues) { - gh issue close $issue --comment 'Closing this issue as newer community metrics are available.' + Write-Output "Closing issue $issue" } env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 13fa55d194c7d95df4319f43712e453e5e9bf7dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Fri, 31 May 2024 16:19:42 +0200 Subject: [PATCH 06/12] Do we need a repo reference? --- .github/workflows/community_metrics.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/community_metrics.yml b/.github/workflows/community_metrics.yml index bd56e6974e8..15d8089b8c3 100644 --- a/.github/workflows/community_metrics.yml +++ b/.github/workflows/community_metrics.yml @@ -14,7 +14,7 @@ jobs: - name: Close Previous Issue shell: pwsh run: | - $issues = gh issue list --repo '${{ github.repository }}' --label 'community metrics' --state open --json number --jq '.[].number' + $issues = gh issue list --label 'community metrics' --state open --json number --jq '.[].number' foreach ($issue in $issues) { Write-Output "Closing issue $issue" From a3f417754e798fcb661d4d31716af2e82b9c6ef8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Fri, 31 May 2024 16:20:11 +0200 Subject: [PATCH 07/12] Revert "Do we need a repo reference?" This reverts commit 13fa55d194c7d95df4319f43712e453e5e9bf7dc. --- .github/workflows/community_metrics.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/community_metrics.yml b/.github/workflows/community_metrics.yml index 15d8089b8c3..bd56e6974e8 100644 --- a/.github/workflows/community_metrics.yml +++ b/.github/workflows/community_metrics.yml @@ -14,7 +14,7 @@ jobs: - name: Close Previous Issue shell: pwsh run: | - $issues = gh issue list --label 'community metrics' --state open --json number --jq '.[].number' + $issues = gh issue list --repo '${{ github.repository }}' --label 'community metrics' --state open --json number --jq '.[].number' foreach ($issue in $issues) { Write-Output "Closing issue $issue" From 24269b2e2f247e3527483af668de98eb00253f03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Fri, 31 May 2024 16:20:51 +0200 Subject: [PATCH 08/12] Add repo reference to gh issue close too --- .github/workflows/community_metrics.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/community_metrics.yml b/.github/workflows/community_metrics.yml index bd56e6974e8..028d19ea1ab 100644 --- a/.github/workflows/community_metrics.yml +++ b/.github/workflows/community_metrics.yml @@ -17,7 +17,7 @@ jobs: $issues = gh issue list --repo '${{ github.repository }}' --label 'community metrics' --state open --json number --jq '.[].number' foreach ($issue in $issues) { - Write-Output "Closing issue $issue" + gh issue close $issue --repo '${{ github.repository }}' --comment 'Closing this issue as newer community metrics are available.' } env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 68ed29b7be7a29d1be71ba19a5a47536436f9cd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Fri, 31 May 2024 16:26:08 +0200 Subject: [PATCH 09/12] Docs --- .github/workflows/community_metrics.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/community_metrics.yml b/.github/workflows/community_metrics.yml index 028d19ea1ab..0d4e0045065 100644 --- a/.github/workflows/community_metrics.yml +++ b/.github/workflows/community_metrics.yml @@ -14,6 +14,8 @@ jobs: - name: Close Previous Issue shell: pwsh run: | + # Without the --repo switch, the GH CLI will try to look it up from the current clone, which doesn't exist + # because we don't otherwise need checkout. $issues = gh issue list --repo '${{ github.repository }}' --label 'community metrics' --state open --json number --jq '.[].number' foreach ($issue in $issues) { From c56a9a6e02b42a03cf5200c827bd22e8f56365ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Fri, 31 May 2024 16:26:19 +0200 Subject: [PATCH 10/12] Let's try closing the issue without a comment --- .github/workflows/community_metrics.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/community_metrics.yml b/.github/workflows/community_metrics.yml index 0d4e0045065..333e33d00d3 100644 --- a/.github/workflows/community_metrics.yml +++ b/.github/workflows/community_metrics.yml @@ -19,7 +19,7 @@ jobs: $issues = gh issue list --repo '${{ github.repository }}' --label 'community metrics' --state open --json number --jq '.[].number' foreach ($issue in $issues) { - gh issue close $issue --repo '${{ github.repository }}' --comment 'Closing this issue as newer community metrics are available.' + gh issue close $issue --repo '${{ github.repository }}' } env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 6c1d5134693eb40042be53f1465937c5d6060355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Fri, 31 May 2024 16:27:11 +0200 Subject: [PATCH 11/12] Revert "Let's try closing the issue without a comment" This reverts commit c56a9a6e02b42a03cf5200c827bd22e8f56365ab. --- .github/workflows/community_metrics.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/community_metrics.yml b/.github/workflows/community_metrics.yml index 333e33d00d3..0d4e0045065 100644 --- a/.github/workflows/community_metrics.yml +++ b/.github/workflows/community_metrics.yml @@ -19,7 +19,7 @@ jobs: $issues = gh issue list --repo '${{ github.repository }}' --label 'community metrics' --state open --json number --jq '.[].number' foreach ($issue in $issues) { - gh issue close $issue --repo '${{ github.repository }}' + gh issue close $issue --repo '${{ github.repository }}' --comment 'Closing this issue as newer community metrics are available.' } env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 967b09903edac0f136b3f0fb41df8b771deef5fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Fri, 31 May 2024 16:32:18 +0200 Subject: [PATCH 12/12] Revert to full workflow --- .github/workflows/community_metrics.yml | 72 ++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/.github/workflows/community_metrics.yml b/.github/workflows/community_metrics.yml index 0d4e0045065..5005475e9f0 100644 --- a/.github/workflows/community_metrics.yml +++ b/.github/workflows/community_metrics.yml @@ -1,7 +1,10 @@ name: Community Metrics on: - pull_request: - + workflow_dispatch: + schedule: + # Run on the first day of every month at 2:19 AM UTC. + - cron: '19 2 1 * *' + permissions: issues: write pull-requests: read @@ -11,6 +14,63 @@ jobs: name: Generate Community Metrics runs-on: ubuntu-latest steps: + - name: Get Dates For Last Month + shell: pwsh + run: | + # Calculate the first day of the previous month. + $firstDay = (Get-Date).AddMonths(-1).ToString("yyyy-MM-01") + + # Calculate the last day of the previous month. + $lastDay = (Get-Date $firstDay).AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd") + + # Set an environment variable with the date range. + Write-Output "$firstDay..$lastDay" + Write-Output "LAST_MONTH=$firstDay..$lastDay" >> $env:GITHUB_ENV + + - name: Compute Issue Metrics + uses: github/issue-metrics@v3 + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SEARCH_QUERY: 'repo:OrchardCMS/OrchardCore is:issue created:${{ env.LAST_MONTH }} -reason:"not planned" -label:"community metrics"' + HIDE_TIME_TO_ANSWER: true + + - name: Rename Issue Metrics File + shell: pwsh + run: | + # Renaming the file wouldn't work since other scripts will be denied access to it for some reason. + Add-Content -Path ./community_metrics.md -Value (Get-Content -Path ./issue_metrics.md -Raw) + + - name: Compute Pull Request Metrics + uses: github/issue-metrics@v3 + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SEARCH_QUERY: 'repo:OrchardCMS/OrchardCore is:pr created:${{ env.LAST_MONTH }} -label:dontmerge -label:notready -is:draft' + HIDE_TIME_TO_ANSWER: true + + - name: Concatenate Issue and Pull Request Metrics + shell: pwsh + run: | + $content = (Get-Content -Path ./issue_metrics.md -Raw) -replace '# Issue Metrics', '# Pull Request Metrics' + Add-Content -Path ./community_metrics.md -Value ([Environment]::NewLine + $content) + + - name: Compute Q&A Discussion Request Metrics + uses: github/issue-metrics@v3 + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SEARCH_QUERY: 'repo:OrchardCMS/OrchardCore type:discussions created:${{ env.LAST_MONTH }} category:Q&A' + HIDE_TIME_TO_CLOSE: true + + - name: Concatenate Issue/PR and Discussion Metrics + shell: pwsh + run: | + $content = (Get-Content -Path ./issue_metrics.md -Raw) -replace '# Issue Metrics', '# Discussion Metrics' + Add-Content -Path ./community_metrics.md -Value ([Environment]::NewLine + $content) + + - name: Display Issue Metrics in Summary + shell: pwsh + run: | + Get-Content ./community_metrics.md >> $env:GITHUB_STEP_SUMMARY + - name: Close Previous Issue shell: pwsh run: | @@ -24,3 +84,11 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Create Issue + # v5.0.0 + uses: peter-evans/create-issue-from-file@24452a72d85239eacf1468b0f1982a9f3fec4c94 + with: + title: Monthly community metrics report for ${{ env.LAST_MONTH }} + token: ${{ secrets.GITHUB_TOKEN }} + content-filepath: ./community_metrics.md + labels: community metrics