-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better install instructions #53
Comments
Hi @paul-uz! Thanks for creating this issue! I agree we need some better instructions. It's easiest in terms of setup if you use the repo that you want scanned as the repo where you run this action. Here is an example: I'd like to get statistics on github.com/zkoppert/project-a and I would also like the resulting reports to be opened as issues in that repo.
name: Monthly issue metrics
on:
workflow_dispatch:
schedule:
- cron: '3 2 1 * *'
permissions:
issues: write
jobs:
build:
name: issue metrics
runs-on: ubuntu-latest
steps:
- name: Get dates for last month
shell: bash
run: |
# Get the current date
current_date=$(date +'%Y-%m-%d')
# Calculate the previous month
previous_date=$(date -d "$current_date -1 month" +'%Y-%m-%d')
# Extract the year and month from the previous date
previous_year=$(date -d "$previous_date" +'%Y')
previous_month=$(date -d "$previous_date" +'%m')
# Calculate the first day of the previous month
first_day=$(date -d "$previous_year-$previous_month-01" +'%Y-%m-%d')
# Calculate the last day of the previous month
last_day=$(date -d "$first_day +1 month -1 day" +'%Y-%m-%d')
echo "$first_day..$last_day"
echo "last_month=$first_day..$last_day" >> "$GITHUB_ENV"
- name: Run issue-metrics tool
uses: github/issue-metrics@v2
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SEARCH_QUERY: 'repo:owner/repo is:issue created:${{ env.last_month }} -reason:"not planned"'
- name: Create issue
uses: peter-evans/create-issue-from-file@v4
with:
title: Monthly issue metrics report
token: ${{ secrets.GITHUB_TOKEN }}
content-filepath: ./issue_metrics.md
assignees: <YOUR_GITHUB_HANDLE_HERE>
Hope that helps! I'll also work on improving the README documentation. |
How do I create the GITHUB_TOKEN secret exactly? EDIT - i'm getting the following error on the step "Run issue-metrics tool" Starting issue-metrics search... I created a personal token in my account, which has access to my organisation repos. Problem is, I don't know what permissions it needs exactly. I selected issues, PRs and some others, as read only, but its still failing. |
GITHUB_TOKEN should be automatically generated as a part of the GitHub action running. More info on that at https://docs.github.com/en/actions/security-guides/automatic-token-authentication. Is your workflow file in the same repository that you are running metrics on? Could you post your workflow file? |
I copied the workflow you posted and just changed the github user name to my own. You say the token should be generated automatically but the instructions talk about creating a secret with a token with correct permissions so now I'm totally confused. |
Here is the decision point on whether or not you need to generate your own token or use the built in one (called GITHUB_TOKEN): If you are running this workflow in the same repository as the one that you are measuring and the issue with the metrics should also appear in that repository then you do not need to create your own token. If you are running this workflow in a different repository from the one you are measuring or you want the resulting issue with the metrics in it to appear in a different repository, then you need to create your own token. |
With regards to the workflow file, you mentioned that you changed the github username. That's great! Did you also change the |
No, I kept the search query the same. That wasn't the issue though, it's the token that's not working. I'm running the action in the report I want to report on, but I get that validation error, so it seems the auto generated token isn't working? Edit - looks like you need to specify the repository in that search query, which I missed. Again, the instructions aren't super clear. Will retry tomorrow with the repo name in. Is there no way around this so it just uses the repository name of the repository the action is in? Seems redundant to have to set it. |
Can you provide succinct instructions on how to set up the 2nd type of token as well, please? |
I've added instructions for the 2nd type of token in this pull request. Let me know if you feel like something is missing there. |
regarding the auto-generated token not working, do you have this in your workflow file: permissions:
issues: write |
Yes, as its in the workflow i copied from you posted here. I fixed the Here is my file name: Monthly issue metrics
on:
workflow_dispatch:
schedule:
- cron: '3 2 1 * *'
permissions:
issues: write
jobs:
build:
name: issue metrics
runs-on: ubuntu-latest
steps:
- name: Get dates for last month
shell: bash
run: |
# Get the current date
current_date=$(date +'%Y-%m-%d')
# Calculate the previous month
previous_date=$(date -d "$current_date -1 month" +'%Y-%m-%d')
# Extract the year and month from the previous date
previous_year=$(date -d "$previous_date" +'%Y')
previous_month=$(date -d "$previous_date" +'%m')
# Calculate the first day of the previous month
first_day=$(date -d "$previous_year-$previous_month-01" +'%Y-%m-%d')
# Calculate the last day of the previous month
last_day=$(date -d "$first_day +1 month -1 day" +'%Y-%m-%d')
echo "$first_day..$last_day"
echo "last_month=$first_day..$last_day" >> "$GITHUB_ENV"
- name: Run issue-metrics tool
uses: github/issue-metrics@v2
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SEARCH_QUERY: 'repo<OWNER/REPO_NAME_HERE> is:issue created:${{ env.last_month }} -reason:"not planned"'
- name: Create issue
uses: peter-evans/create-issue-from-file@v4
with:
title: Monthly issue metrics report
token: ${{ secrets.GITHUB_TOKEN }}
content-filepath: ./issue_metrics.md
assignees: paul-uz I've ommited the owner/repo value as its a private repo |
Seems to be sorted. I was re-running the old workflow, despite editing the file. I triggered a new run and its using the updated file. |
Is that updated file is working as expected? |
It is! I was stupidly re running the previous workflows, thinking it would use the updates I made, but it wasn't. Lesson learnt. Thank you for the help and for updating the docs to help others like me :) |
Can we get some better installation instructions?
I'm struggling to understand what exactly I need to do in order to use this action.
Step 1 states "Create a repository to host this GitHub Action or select an existing repository."
Do I fork this repo? Clone it then upload to me own account? Or if I select a pre-existing repo, is it the one I want to be scanned?
Step 2 "Create the env values from the sample workflow below (GH_TOKEN, SEARCH_QUERY) with your information as repository secrets. More info on creating secrets can be found here. Note: Your GitHub token will need to have read access to the repository in the organization that you want evaluated"
Where do I put these env vars? I see an .env-example file, so I guess I need an .env file, but where would it go? In the repo I want scanning, or in some other repo (see issues with step 1)
The text was updated successfully, but these errors were encountered: