Skip to content

Commit b34c11e

Browse files
authored
Merge pull request #23 from github/calc-time-range
Add example for calculated time range
2 parents 7736010 + 2da760c commit b34c11e

File tree

1 file changed

+58
-2
lines changed

1 file changed

+58
-2
lines changed

README.md

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ Below are the allowed configuration options:
3232
| `REPOSITORY_URL` | true | | The repository to scan for issues. |
3333
| `SEARCH_QUERY` | true | | The query by which you can filter issues/prs |
3434

35-
### Example workflow
35+
### Example workflows
36+
37+
#### Calculated Time Example
38+
This workflow searches for the issues created last month, and generates an issue with metrics.
3639

3740
```yaml
3841
name: Monthly issue metrics
@@ -41,6 +44,59 @@ on:
4144
schedule:
4245
- cron: '3 2 1 * *'
4346

47+
jobs:
48+
build:
49+
name: issue metrics
50+
runs-on: ubuntu-latest
51+
52+
steps:
53+
54+
- name: Get dates for last month
55+
shell: bash
56+
run: |
57+
# Get the current date
58+
current_date=$(date +'%Y-%m-%d')
59+
60+
# Calculate the previous month
61+
previous_date=$(date -d "$current_date -1 month" +'%Y-%m-%d')
62+
63+
# Extract the year and month from the previous date
64+
previous_year=$(date -d "$previous_date" +'%Y')
65+
previous_month=$(date -d "$previous_date" +'%m')
66+
67+
# Calculate the first day of the previous month
68+
first_day=$(date -d "$previous_year-$previous_month-01" +'%Y-%m-%d')
69+
70+
# Calculate the last day of the previous month
71+
last_day=$(date -d "$first_day +1 month -1 day" +'%Y-%m-%d')
72+
73+
echo "$first_day..$last_day"
74+
echo "last_month=$first_day..$last_day" >> "$GITHUB_ENV"
75+
76+
- name: Run issue-metrics tool
77+
uses: github/issue-metrics@v1
78+
env:
79+
GH_TOKEN: ${{ secrets.GH_TOKEN }}
80+
REPOSITORY_URL: https://github.com/owner/repo
81+
SEARCH_QUERY: 'is:issue created:${{ env.last_month }} -reason:"not planned"'
82+
83+
- name: Create issue
84+
uses: peter-evans/create-issue-from-file@v4
85+
with:
86+
title: Monthly issue metrics report
87+
content-filepath: ./issue_metrics.md
88+
assignees: <YOUR_GITHUB_HANDLE_HERE>
89+
90+
```
91+
92+
#### Fixed Time Example
93+
This workflow searches for the issues created between 2023-05-01..2023-05-31, and generates an issue with metrics.
94+
95+
```yaml
96+
name: Monthly issue metrics
97+
on:
98+
workflow_dispatch:
99+
44100
jobs:
45101
build:
46102
name: issue metrics
@@ -85,7 +141,7 @@ Both issues and pull requests opened in May 2023:
85141
Both issues and pull requests closed in May 2023 (may have been open in May or earlier):
86142
- `closed:2023-05-01..2023-05-31`
87143

88-
OK, but what if I want both open or closed issues and pull requests? Due to limitations in issue search (no ability for an or pattern), you will need to run the action twice, once for opened and once for closed. Here is an example workflow that does this:
144+
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:
89145

90146
```yaml
91147
name: Monthly issue metrics

0 commit comments

Comments
 (0)