Skip to content

Commit

Permalink
docs: add README: example that demonstrates multiple search queries w…
Browse files Browse the repository at this point in the history
…ith 1 report #49
  • Loading branch information
Okabe-Junya committed Aug 2, 2023
1 parent 92b849a commit 3719832
Showing 1 changed file with 88 additions and 12 deletions.
100 changes: 88 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
build:
name: issue metrics
runs-on: ubuntu-latest

steps:

- name: Get dates for last month
Expand All @@ -85,7 +85,7 @@ jobs:
# 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"
Expand Down Expand Up @@ -122,7 +122,7 @@ jobs:
build:
name: issue metrics
runs-on: ubuntu-latest

steps:

- name: Run issue-metrics tool
Expand All @@ -141,6 +141,82 @@ jobs:

```

#### Multiple Repositories Example

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.

```yaml
name: Monthly issue metrics
on:
workflow_dispatch:

permissions:
issues: write
pull-requests: read

jobs:
build:
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: Get issue metrics (repo1)
uses: github/issue-metrics@v2
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SEARCH_QUERY: 'repo:owner/repo is:issue created:2023-05-01..2023-05-31 -reason:"not planned"'

- name: Copy issue metrics (repo1)
run: |
cp ./issue_metrics.md ./issue_metrics_repo1.md
- name: Get issue metrics (repo2)
uses: github/issue-metrics@v2
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SEARCH_QUERY: 'repo:owner/repo is:issue created:2023-05-01..2023-05-31 -reason:"not planned"'

- name: Copy issue metrics (repo2)
run: |
cp ./issue_metrics.md ./issue_metrics_repo2.md
- name: change owner of issue_metrics.md
run: |
sudo chown runner:runner ./issue_metrics.md
- name: Merge issue metrics
run: |
rm ./issue_metrics.md
echo "## repo1" >> ./issue_metrics.md
cat ./issue_metrics_repo1.md >> ./issue_metrics.md
echo "## repo2" >> ./issue_metrics.md
cat ./issue_metrics_repo2.md >> ./issue_metrics.md
sed -i '/# Issue Metrics/d' ./issue_metrics.md
sed -i '/_This report was generated with the [Issue Metrics Action](https://github.com/github/issue-metrics)_/d' ./issue_metrics.md
echo "_This report was generated with the [Issue Metrics Action](https://github.com/github/issue-metrics)_" >> ./issue_metrics.md
- name: Create issue
uses: peter-evans/create-issue-from-file@v4
with:
title: Monthly issue metrics report (dev)
token: ${{ secrets.GITHUB_TOKEN }}
content-filepath: ./issue_metrics.md
assignees: <YOUR_GITHUB_HANDLE_HERE>
```
## SEARCH_QUERY
Issues or Pull Requests? Open or closed?
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:
Expand Down Expand Up @@ -169,7 +245,7 @@ Both issues and pull requests opened in May 2023:
Both issues and pull requests closed in May 2023 (may have been open in May or earlier):
- `repo:owner/repo closed:2023-05-01..2023-05-31`

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:
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:

```yaml
name: Monthly issue metrics
Expand All @@ -188,7 +264,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Run issue-metrics tool for issues and prs opened in May 2023
uses: github/issue-metrics@v2
env:
Expand All @@ -202,7 +278,7 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
content-filepath: ./issue_metrics.md
assignees: <YOUR_GITHUB_HANDLE_HERE>
- name: Run issue-metrics tool for issues and prs closed in May 2023
uses: github/issue-metrics@v2
env:
Expand Down Expand Up @@ -238,7 +314,7 @@ jobs:
build:
name: issue metrics
runs-on: ubuntu-latest
steps:
- name: Run issue-metrics tool
Expand Down Expand Up @@ -378,18 +454,18 @@ jobs:
build:
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"
Expand All @@ -413,7 +489,7 @@ jobs:
title: Monthly issue metrics report
token: ${{ secrets.GITHUB_TOKEN }}
content-filepath: ./issue_metrics.md
assignees: ${{ env.TEAM_MEMBERS }}
assignees: ${{ env.TEAM_MEMBERS }}
```

## Local usage without Docker
Expand All @@ -426,4 +502,4 @@ jobs:

## License

[MIT](LICENSE)
[MIT](LICENSE)

0 comments on commit 3719832

Please sign in to comment.