Skip to content

Commit

Permalink
Create pull_requests_to_csv.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
n2020h authored Jul 22, 2024
1 parent 0bd573f commit e3a668a
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/pull_requests_to_csv.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: List Pull Requests and Output as CSV

on:
push:
branches:
- n2020h-issues-to-csv
workflow_dispatch:
schedule:
- cron: '0 0 * * *' # Runs daily at midnight
pull_request:
types: [opened, closed, reopened]
branches:
- n2020h-issues-to-csv

jobs:
list-pull-requests:
runs-on: ubuntu-latest

steps:
# Checkout the repository to access any scripts or tools you might need
- name: Checkout repository
uses: actions/checkout@v3

# Set up Node.js to use jq command
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '16'

# Fetch pull requests from GitHub API and generate CSV
- name: Fetch pull requests and generate CSV
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Fetch pull requests data and save it to pulls.json
curl -H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/pulls?state=all \
-o pulls.json
# Use jq to parse pulls.json and generate my_org_PRs.csv
jq -r '[.[] | {
"PR Number": .number,
"Title": .title,
"Description": .body,
"Author": .user.login,
"State": .state,
"Number of Commits": .commits,
"Number of Files Changed": .changed_files,
"Labels": (.labels | map(.name) | join(",")),
"Assignees": (.assignees | map(.login) | join(",")),
"Linked Issues": ([capture("#(?<number>\\d+)") | .number] | join(",")),
"Reviewers": (.requested_reviewers | map(.login) | join(","))
}] | (first | keys_unsorted) as $keys | $keys, map([.[ $keys[] ]])[] | @csv' \
pulls.json > hackforla_pull_requests.csv
# Commit and push the generated CSV to the repository
- name: Commit and push CSV
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add my_org_PRs.csv
git commit -m "Update pull requests CSV"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit e3a668a

Please sign in to comment.