Skip to content

Commit a9fa85d

Browse files
authored
Create pattern-metrics.yaml (#593)
* 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
1 parent bb13f6b commit a9fa85d

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
name: Monthly issue metrics
2+
on:
3+
workflow_dispatch:
4+
schedule:
5+
- cron: '3 2 1 * *'
6+
7+
permissions:
8+
issues: write
9+
pull-requests: read
10+
11+
jobs:
12+
issue-metrics:
13+
name: issue metrics
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
18+
- name: Get dates for last month
19+
shell: bash
20+
run: |
21+
# Calculate the first day of the previous month
22+
first_day=$(date -d "last month" +%Y-%m-01)
23+
24+
# Calculate the last day of the previous month
25+
last_day=$(date -d "$first_day +1 month -1 day" +%Y-%m-%d)
26+
27+
#Set an environment variable with the date range
28+
echo "$first_day..$last_day"
29+
echo "last_month=$first_day..$last_day" >> "$GITHUB_ENV"
30+
31+
- name: Check out the code so we can get the CODEOWNERS names
32+
uses: actions/checkout@v4
33+
with:
34+
sparse-checkout: |
35+
.github/CODEOWNERS
36+
sparse-checkout-cone-mode: false
37+
38+
- name: Get usernames from CODEOWNERS file
39+
shell: bash
40+
run: |
41+
# open a file called CODEOWNERS and load the content into a variable
42+
CODEOWNERS_FILE=$(cat .github/CODEOWNERS)
43+
44+
# Extract words from CODEOWNERS that start with @ and convert them into a comma-separated string
45+
# ie, "-author:spier -author:zkoppert"
46+
# This will be used to filter out these codeowners from certain stats in later steps
47+
CODEOWNERS_FILTER=$(echo $CODEOWNERS_FILE | grep -o "@[a-zA-Z0-9\-]*" | sed 's/@/-author:/g' | tr '\n' ' ')
48+
49+
# Print usernames to terminal for easy debugging
50+
echo "CODEOWNERS_FILTER: $CODEOWNERS_FILTER"
51+
52+
# Store CODEOWNERS_FILTERto GitHub Action environment (not permanent)
53+
echo "CODEOWNERS_FILTER=$CODEOWNERS_FILTER" >> "$GITHUB_ENV"
54+
55+
- name: Run issue-metrics tool
56+
uses: github/issue-metrics@v2
57+
env:
58+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59+
SEARCH_QUERY: 'repo:InnerSourceCommons/InnerSourcePatterns is:issue created:${{ env.last_month }} -reason:"not planned" ${{ env.CODEOWNERS_FILTER }}'
60+
HIDE_TIME_TO_ANSWER: "True"
61+
HIDE_LABEL_METRICS: "True"
62+
63+
- name: Create issue
64+
uses: peter-evans/create-issue-from-file@v4
65+
with:
66+
title: Monthly New Issues Data ${{ env.last_month }}
67+
token: ${{ secrets.GITHUB_TOKEN }}
68+
content-filepath: ./issue_metrics.md
69+
assignees: spier
70+
71+
pr-metrics:
72+
name: pull request metrics
73+
runs-on: ubuntu-latest
74+
75+
steps:
76+
77+
- name: Get dates for last month
78+
shell: bash
79+
run: |
80+
# Calculate the first day of the previous month
81+
first_day=$(date -d "last month" +%Y-%m-01)
82+
83+
# Calculate the last day of the previous month
84+
last_day=$(date -d "$first_day +1 month -1 day" +%Y-%m-%d)
85+
86+
#Set an environment variable with the date range
87+
echo "$first_day..$last_day"
88+
echo "last_month=$first_day..$last_day" >> "$GITHUB_ENV"
89+
90+
- name: Check out the code so we can get the CODEOWNERS names
91+
uses: actions/checkout@v4
92+
93+
- name: Get usernames from CODEOWNERS file
94+
shell: bash
95+
run: |
96+
# open a file called CODEOWNERS and load the content into a variable
97+
CODEOWNERS_FILE=$(cat .github/CODEOWNERS)
98+
99+
# Extract words from CODEOWNERS that start with @ and convert them into a comma-separated string
100+
# ie, "-author:spier -author:zkoppert"
101+
# This will be used to filter out these codeowners from certain stats in later steps
102+
CODEOWNERS_FILTER=$(echo $CODEOWNERS_FILE | grep -o "@[a-zA-Z0-9\-]*" | sed 's/@/-author:/g' | tr '\n' ' ')
103+
104+
# Print usernames to terminal for easy debugging
105+
echo "CODEOWNERS_FILTER: $CODEOWNERS_FILTER"
106+
107+
# Store CODEOWNERS_FILTERto GitHub Action environment (not permanent)
108+
echo "CODEOWNERS_FILTER=$CODEOWNERS_FILTER" >> "$GITHUB_ENV"
109+
110+
- name: Run issue-metrics tool
111+
uses: github/issue-metrics@v2
112+
env:
113+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
114+
SEARCH_QUERY: 'repo:InnerSourceCommons/InnerSourcePatterns is:pr created:${{ env.last_month }} -reason:"not planned" ${{ env.CODEOWNERS_FILTER }}'
115+
HIDE_TIME_TO_ANSWER: "True"
116+
HIDE_LABEL_METRICS: "True"
117+
118+
- name: Create issue
119+
uses: peter-evans/create-issue-from-file@v4
120+
with:
121+
title: Monthly New Pull Request Data ${{ env.last_month }}
122+
token: ${{ secrets.GITHUB_TOKEN }}
123+
content-filepath: ./issue_metrics.md
124+
assignees: spier

0 commit comments

Comments
 (0)