From 33ad598a470d4b3eb4f17c7424c7bd94acf4a555 Mon Sep 17 00:00:00 2001 From: Zack Koppert Date: Mon, 9 Oct 2023 14:11:42 -0700 Subject: [PATCH 1/2] Create pattern-metrics.yaml Getting started measuring pattern metrics. Related to #565. This pull request implements - Time to first response metrics for new issues (excluding codeowners created) recurring every month - Time to first response metrics for new pull requests (excluding codeowners created) recurring every month --- .github/workflows/pattern-metrics.yaml | 120 +++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 .github/workflows/pattern-metrics.yaml diff --git a/.github/workflows/pattern-metrics.yaml b/.github/workflows/pattern-metrics.yaml new file mode 100644 index 000000000..35fc05b6a --- /dev/null +++ b/.github/workflows/pattern-metrics.yaml @@ -0,0 +1,120 @@ +name: Monthly issue metrics +on: + workflow_dispatch: + schedule: + - cron: '3 2 1 * *' + +permissions: + issues: write + pull-requests: read + +jobs: + issue-metrics: + name: issue metrics + runs-on: ubuntu-latest + + steps: + + - name: Get dates for last month + shell: bash + run: | + # Calculate the first day of the previous month + first_day=$(date -d "last month" +%Y-%m-01) + + # Calculate the last day of the previous month + last_day=$(date -d "$first_day +1 month -1 day" +%Y-%m-%d) + + #Set an environment variable with the date range + echo "$first_day..$last_day" + echo "last_month=$first_day..$last_day" >> "$GITHUB_ENV" + + - name: Check out the code so we can get the CODEOWNERS names + uses: actions/checkout@v4 + + - name: Get usernames from CODEOWNERS file + shell: bash + run: | + # open a file called CODEOWNERS and load the content into a variable + CODEOWNERS_FILE=$(cat .github/CODEOWNERS) + + # Extract words from CODEOWNERS that start with @ and convert them into a comma-separated string + # ie, "-author:spier -author:zkoppert" + # This will be used to filter out these codeowners from certain stats in later steps + CODEOWNERS_FILTER=$(echo $CODEOWNERS_FILE | grep -o "@[a-zA-Z0-9\-]*" | sed 's/@/-author:/g' | tr '\n' ' ') + + # Print usernames to terminal for easy debugging + echo "CODEOWNERS_FILTER: $CODEOWNERS_FILTER" + + # Store CODEOWNERS_FILTERto GitHub Action environment (not permanent) + echo "CODEOWNERS_FILTER=$CODEOWNERS_FILTER" >> "$GITHUB_ENV" + + - name: Run issue-metrics tool + uses: github/issue-metrics@v2 + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SEARCH_QUERY: 'repo:InnerSourceCommons/InnerSourcePatterns is:issue created:${{ env.last_month }} -reason:"not planned" ${{ env.CODEOWNERS_FILTER }}' + HIDE_TIME_TO_ANSWER: "True" + HIDE_LABEL_METRICS: "True" + + - name: Create issue + uses: peter-evans/create-issue-from-file@v4 + with: + title: Monthly New Issues Data ${{ env.last_month }} + token: ${{ secrets.GITHUB_TOKEN }} + content-filepath: ./issue_metrics.md + assignees: spier + + pr-metrics: + name: pull request metrics + runs-on: ubuntu-latest + + steps: + + - name: Get dates for last month + shell: bash + run: | + # Calculate the first day of the previous month + first_day=$(date -d "last month" +%Y-%m-01) + + # Calculate the last day of the previous month + last_day=$(date -d "$first_day +1 month -1 day" +%Y-%m-%d) + + #Set an environment variable with the date range + echo "$first_day..$last_day" + echo "last_month=$first_day..$last_day" >> "$GITHUB_ENV" + + - name: Check out the code so we can get the CODEOWNERS names + uses: actions/checkout@v4 + + - name: Get usernames from CODEOWNERS file + shell: bash + run: | + # open a file called CODEOWNERS and load the content into a variable + CODEOWNERS_FILE=$(cat .github/CODEOWNERS) + + # Extract words from CODEOWNERS that start with @ and convert them into a comma-separated string + # ie, "-author:spier -author:zkoppert" + # This will be used to filter out these codeowners from certain stats in later steps + CODEOWNERS_FILTER=$(echo $CODEOWNERS_FILE | grep -o "@[a-zA-Z0-9\-]*" | sed 's/@/-author:/g' | tr '\n' ' ') + + # Print usernames to terminal for easy debugging + echo "CODEOWNERS_FILTER: $CODEOWNERS_FILTER" + + # Store CODEOWNERS_FILTERto GitHub Action environment (not permanent) + echo "CODEOWNERS_FILTER=$CODEOWNERS_FILTER" >> "$GITHUB_ENV" + + - name: Run issue-metrics tool + uses: github/issue-metrics@v2 + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SEARCH_QUERY: 'repo:InnerSourceCommons/InnerSourcePatterns is:pr created:${{ env.last_month }} -reason:"not planned" ${{ env.CODEOWNERS_FILTER }}' + HIDE_TIME_TO_ANSWER: "True" + HIDE_LABEL_METRICS: "True" + + - name: Create issue + uses: peter-evans/create-issue-from-file@v4 + with: + title: Monthly New Pull Request Data ${{ env.last_month }} + token: ${{ secrets.GITHUB_TOKEN }} + content-filepath: ./issue_metrics.md + assignees: spier From 828bb0258aebd591c4fa499a895af91f94f9f17c Mon Sep 17 00:00:00 2001 From: Zack Koppert Date: Tue, 10 Oct 2023 10:56:04 -0700 Subject: [PATCH 2/2] Only grab code that we need Co-authored-by: Sebastian Spier --- .github/workflows/pattern-metrics.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/pattern-metrics.yaml b/.github/workflows/pattern-metrics.yaml index 35fc05b6a..82eed8d51 100644 --- a/.github/workflows/pattern-metrics.yaml +++ b/.github/workflows/pattern-metrics.yaml @@ -30,6 +30,10 @@ jobs: - name: Check out the code so we can get the CODEOWNERS names uses: actions/checkout@v4 + with: + sparse-checkout: | + .github/CODEOWNERS + sparse-checkout-cone-mode: false - name: Get usernames from CODEOWNERS file shell: bash