From d4461a55da8ef231d6a0759bcbff1cb980bfbdda Mon Sep 17 00:00:00 2001 From: Andrea Date: Fri, 27 Sep 2024 16:17:44 -0700 Subject: [PATCH 1/5] docs: instructions on verifying token access to a repository --- README.md | 3 +- docs/verify-token-access-to-repository.md | 65 +++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 docs/verify-token-access-to-repository.md diff --git a/README.md b/README.md index 11f6f8b..02c42b3 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ name: Monthly issue metrics on: workflow_dispatch: schedule: - - cron: "3 2 1 * *" + - cron: '3 2 1 * *' permissions: contents: read @@ -110,6 +110,7 @@ All feedback regarding our GitHub Actions, as a whole, should be communicated th - Do this by creating a [GitHub API token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic) with permissions to read the repository and write issues. - Then take the value of the API token you just created, and [create a repository secret](https://docs.github.com/en/actions/security-guides/encrypted-secrets) where the name of the secret is `GH_TOKEN` and the value of the secret the API token. - Then finally update the workflow file to use that repository secret by changing `GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}` to `GH_TOKEN: ${{ secrets.GH_TOKEN }}`. The name of the secret can really be anything. It just needs to match between when you create the secret name and when you refer to it in the workflow file. + - Help on verifying your token's access to your repository [here](docs/verify-token-access-to-repository.md) 6. If you want the resulting issue with the metrics in it to appear in a different repository other than the one the workflow file runs in, update the line `token: ${{ secrets.GITHUB_TOKEN }}` with your own GitHub API token stored as a repository secret. - This process is the same as described in the step above. More info on creating secrets can be found [here](https://docs.github.com/en/actions/security-guides/encrypted-secrets). 7. Commit the workflow file to the default branch (often `master` or `main`) diff --git a/docs/verify-token-access-to-repository.md b/docs/verify-token-access-to-repository.md new file mode 100644 index 0000000..3b0c5fe --- /dev/null +++ b/docs/verify-token-access-to-repository.md @@ -0,0 +1,65 @@ +## Verify Token Access to Repository + +Github PAT token access can be confusing. Here's a quick way to test if the token you're using is authorized to access your repository. + +**Remove this snippet after you've verified your token.** + +- Make sure you follow the token setup instructions [here](https://github.com/github/issue-metrics/tree/main?tab=readme-ov-file#use-as-a-github-action) first. + +- Replace `{owner/repo}` with your own repo information. + +- Add this snippet to your workflow.yml. + +``` +- name: Check GitHub token permissions + run: | + curl -H "Authorization: token ${{ secrets.GH_TOKEN }}" https://api.github.com/repos/{owner/repo} +``` + +- Go to your repository Actions in Github and run your job. +- In the job run details, click into the results of `Check Github token permissions` +- You should see your token details with no errors. + +Example of the snippet in the full workflow: + +``` +name: Monthly issue metrics +on: + workflow_dispatch: + schedule: + - cron: '3 2 1 * *' + +permissions: + contents: read + +jobs: + build: + name: issue metrics + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: read + + steps: + - name: Check GitHub token permissions + run: | + curl -H "Authorization: token ${{ secrets.GH_TOKEN }}" https://api.github.com/{owner/repo} + - 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: Run issue-metrics tool + uses: github/issue-metrics@v3 + env: + GH_TOKEN: ${{ secrets.GH_TOKEN }} + SEARCH_QUERY: 'repo:{owner/repo} is:issue created:${{ env.last_month }}' +``` From f4ae9f177fe38aad012affb814426f42b65cea99 Mon Sep 17 00:00:00 2001 From: Andrea Date: Fri, 27 Sep 2024 16:24:31 -0700 Subject: [PATCH 2/5] docs: prettier updates --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 02c42b3..a88e47b 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ name: Monthly issue metrics on: workflow_dispatch: schedule: - - cron: '3 2 1 * *' + - cron: "3 2 1 * *" permissions: contents: read From c32ea51204c14a813a12a6268284ba992c4d5814 Mon Sep 17 00:00:00 2001 From: Andrea Date: Fri, 27 Sep 2024 16:26:03 -0700 Subject: [PATCH 3/5] docs: language update --- docs/verify-token-access-to-repository.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/verify-token-access-to-repository.md b/docs/verify-token-access-to-repository.md index 3b0c5fe..d69a41b 100644 --- a/docs/verify-token-access-to-repository.md +++ b/docs/verify-token-access-to-repository.md @@ -6,7 +6,7 @@ Github PAT token access can be confusing. Here's a quick way to test if the toke - Make sure you follow the token setup instructions [here](https://github.com/github/issue-metrics/tree/main?tab=readme-ov-file#use-as-a-github-action) first. -- Replace `{owner/repo}` with your own repo information. +- Replace `{owner/repo}` with your own repository information. - Add this snippet to your workflow.yml. From 57de64ac248dc1de8daa8bf46bcc0eb55ca72276 Mon Sep 17 00:00:00 2001 From: Andrea Date: Fri, 27 Sep 2024 16:30:37 -0700 Subject: [PATCH 4/5] docs: correct more linting CI errors --- docs/verify-token-access-to-repository.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/verify-token-access-to-repository.md b/docs/verify-token-access-to-repository.md index d69a41b..b5ccc13 100644 --- a/docs/verify-token-access-to-repository.md +++ b/docs/verify-token-access-to-repository.md @@ -1,4 +1,4 @@ -## Verify Token Access to Repository +# Verify Token Access to Repository Github PAT token access can be confusing. Here's a quick way to test if the token you're using is authorized to access your repository. @@ -10,19 +10,19 @@ Github PAT token access can be confusing. Here's a quick way to test if the toke - Add this snippet to your workflow.yml. -``` +```yml - name: Check GitHub token permissions run: | curl -H "Authorization: token ${{ secrets.GH_TOKEN }}" https://api.github.com/repos/{owner/repo} ``` - Go to your repository Actions in Github and run your job. -- In the job run details, click into the results of `Check Github token permissions` +- In the job run details, click into the results of `Check GitHub token permissions` - You should see your token details with no errors. Example of the snippet in the full workflow: -``` +```yml name: Monthly issue metrics on: workflow_dispatch: From 2070ad283720c3f4d7d80a449aae3caaa2424831 Mon Sep 17 00:00:00 2001 From: Andrea Date: Fri, 27 Sep 2024 16:34:44 -0700 Subject: [PATCH 5/5] docs: more lint fixes --- docs/verify-token-access-to-repository.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/verify-token-access-to-repository.md b/docs/verify-token-access-to-repository.md index b5ccc13..25a4f1b 100644 --- a/docs/verify-token-access-to-repository.md +++ b/docs/verify-token-access-to-repository.md @@ -1,6 +1,6 @@ # Verify Token Access to Repository -Github PAT token access can be confusing. Here's a quick way to test if the token you're using is authorized to access your repository. +GitHub PAT token access can be confusing. Here's a quick way to test if the token you're using is authorized to access your repository. **Remove this snippet after you've verified your token.** @@ -16,7 +16,7 @@ Github PAT token access can be confusing. Here's a quick way to test if the toke curl -H "Authorization: token ${{ secrets.GH_TOKEN }}" https://api.github.com/repos/{owner/repo} ``` -- Go to your repository Actions in Github and run your job. +- Go to your repository Actions in GitHub and run your job. - In the job run details, click into the results of `Check GitHub token permissions` - You should see your token details with no errors. @@ -27,7 +27,7 @@ name: Monthly issue metrics on: workflow_dispatch: schedule: - - cron: '3 2 1 * *' + - cron: "3 2 1 * *" permissions: contents: read @@ -61,5 +61,5 @@ jobs: uses: github/issue-metrics@v3 env: GH_TOKEN: ${{ secrets.GH_TOKEN }} - SEARCH_QUERY: 'repo:{owner/repo} is:issue created:${{ env.last_month }}' + SEARCH_QUERY: "repo:{owner/repo} is:issue created:${{ env.last_month }}" ```