Skip to content

Commit f209436

Browse files
authored
Merge pull request #93 from Okabe-Junya/junya/docs/multi-repo-search
docs: Add example that demonstrates multiple search queries
2 parents 6eea04d + 3719832 commit f209436

File tree

1 file changed

+87
-11
lines changed

1 file changed

+87
-11
lines changed

Diff for: README.md

+87-11
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ jobs:
7474
build:
7575
name: issue metrics
7676
runs-on: ubuntu-latest
77-
77+
7878
steps:
7979

8080
- name: Get dates for last month
@@ -85,7 +85,7 @@ jobs:
8585
8686
# Calculate the last day of the previous month
8787
last_day=$(date -d "$first_day +1 month -1 day" +%Y-%m-%d)
88-
88+
8989
#Set an environment variable with the date range
9090
echo "$first_day..$last_day"
9191
echo "last_month=$first_day..$last_day" >> "$GITHUB_ENV"
@@ -122,7 +122,7 @@ jobs:
122122
build:
123123
name: issue metrics
124124
runs-on: ubuntu-latest
125-
125+
126126
steps:
127127

128128
- name: Run issue-metrics tool
@@ -141,6 +141,82 @@ jobs:
141141

142142
```
143143

144+
#### Multiple Repositories Example
145+
146+
This workflow searches for the issues created last month, and generates an issue with metrics. It also uses the `GH_TOKEN` to scan a different repository than the one the workflow file is in.
147+
148+
```yaml
149+
name: Monthly issue metrics
150+
on:
151+
workflow_dispatch:
152+
153+
permissions:
154+
issues: write
155+
pull-requests: read
156+
157+
jobs:
158+
build:
159+
name: issue metrics
160+
runs-on: ubuntu-latest
161+
162+
steps:
163+
- name: Get dates for last month
164+
shell: bash
165+
run: |
166+
# Calculate the first day of the previous month
167+
first_day=$(date -d "last month" +%Y-%m-01)
168+
169+
# Calculate the last day of the previous month
170+
last_day=$(date -d "$first_day +1 month -1 day" +%Y-%m-%d)
171+
172+
#Set an environment variable with the date range
173+
echo "$first_day..$last_day"
174+
echo "last_month=$first_day..$last_day" >> "$GITHUB_ENV"
175+
176+
- name: Get issue metrics (repo1)
177+
uses: github/issue-metrics@v2
178+
env:
179+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
180+
SEARCH_QUERY: 'repo:owner/repo is:issue created:2023-05-01..2023-05-31 -reason:"not planned"'
181+
182+
- name: Copy issue metrics (repo1)
183+
run: |
184+
cp ./issue_metrics.md ./issue_metrics_repo1.md
185+
186+
- name: Get issue metrics (repo2)
187+
uses: github/issue-metrics@v2
188+
env:
189+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
190+
SEARCH_QUERY: 'repo:owner/repo is:issue created:2023-05-01..2023-05-31 -reason:"not planned"'
191+
192+
- name: Copy issue metrics (repo2)
193+
run: |
194+
cp ./issue_metrics.md ./issue_metrics_repo2.md
195+
196+
- name: change owner of issue_metrics.md
197+
run: |
198+
sudo chown runner:runner ./issue_metrics.md
199+
200+
- name: Merge issue metrics
201+
run: |
202+
rm ./issue_metrics.md
203+
echo "## repo1" >> ./issue_metrics.md
204+
cat ./issue_metrics_repo1.md >> ./issue_metrics.md
205+
echo "## repo2" >> ./issue_metrics.md
206+
cat ./issue_metrics_repo2.md >> ./issue_metrics.md
207+
sed -i '/# Issue Metrics/d' ./issue_metrics.md
208+
sed -i '/_This report was generated with the [Issue Metrics Action](https://github.com/github/issue-metrics)_/d' ./issue_metrics.md
209+
echo "_This report was generated with the [Issue Metrics Action](https://github.com/github/issue-metrics)_" >> ./issue_metrics.md
210+
211+
- name: Create issue
212+
uses: peter-evans/create-issue-from-file@v4
213+
with:
214+
title: Monthly issue metrics report (dev)
215+
token: ${{ secrets.GITHUB_TOKEN }}
216+
content-filepath: ./issue_metrics.md
217+
assignees: <YOUR_GITHUB_HANDLE_HERE>
218+
```
219+
144220
## SEARCH_QUERY
145221
Issues or Pull Requests? Open or closed?
146222
This action can be configured to run metrics on discussions, pull requests and/or issues. It is also configurable by whether they were open or closed in the specified time window. Further query options are listed in the [documentation on searching issues and pull requests](https://docs.github.com/en/issues/tracking-your-work-with-issues/filtering-and-searching-issues-and-pull-requests) or the [documentation on searching discussions](https://docs.github.com/en/search-github/searching-on-github/searching-discussions). Search results are limited to 1000 results by the GitHub API. Here are some search query examples:
@@ -169,7 +245,7 @@ Both issues and pull requests opened in May 2023:
169245
Both issues and pull requests closed in May 2023 (may have been open in May or earlier):
170246
- `repo:owner/repo closed:2023-05-01..2023-05-31`
171247

172-
OK, but what if I want both open or closed issues and pull requests? Due to limitations in issue search (no ability for OR logic), you will need to run the action twice, once for opened and once for closed. Here is an example workflow that does this:
248+
OK, but what if I want both open or closed issues and pull requests? Due to limitations in issue search (no ability for OR logic), you will need to run the action twice, once for opened and once for closed. Here is an example workflow that does this:
173249

174250
```yaml
175251
name: Monthly issue metrics
@@ -188,7 +264,7 @@ jobs:
188264
runs-on: ubuntu-latest
189265
190266
steps:
191-
267+
192268
- name: Run issue-metrics tool for issues and prs opened in May 2023
193269
uses: github/issue-metrics@v2
194270
env:
@@ -202,7 +278,7 @@ jobs:
202278
token: ${{ secrets.GITHUB_TOKEN }}
203279
content-filepath: ./issue_metrics.md
204280
assignees: <YOUR_GITHUB_HANDLE_HERE>
205-
281+
206282
- name: Run issue-metrics tool for issues and prs closed in May 2023
207283
uses: github/issue-metrics@v2
208284
env:
@@ -238,7 +314,7 @@ jobs:
238314
build:
239315
name: issue metrics
240316
runs-on: ubuntu-latest
241-
317+
242318
steps:
243319
244320
- name: Run issue-metrics tool
@@ -378,18 +454,18 @@ jobs:
378454
build:
379455
name: issue metrics
380456
runs-on: ubuntu-latest
381-
457+
382458
steps:
383459
384460
- name: Get dates for last month
385461
shell: bash
386462
run: |
387463
# Calculate the first day of the previous month
388464
first_day=$(date -d "last month" +%Y-%m-01)
389-
465+
390466
# Calculate the last day of the previous month
391467
last_day=$(date -d "$first_day +1 month -1 day" +%Y-%m-%d)
392-
468+
393469
#Set an environment variable with the date range
394470
echo "$first_day..$last_day"
395471
echo "last_month=$first_day..$last_day" >> "$GITHUB_ENV"
@@ -413,7 +489,7 @@ jobs:
413489
title: Monthly issue metrics report
414490
token: ${{ secrets.GITHUB_TOKEN }}
415491
content-filepath: ./issue_metrics.md
416-
assignees: ${{ env.TEAM_MEMBERS }}
492+
assignees: ${{ env.TEAM_MEMBERS }}
417493
```
418494

419495
## Local usage without Docker

0 commit comments

Comments
 (0)