Skip to content

Commit 892a336

Browse files
authored
Update pull_requests_to_csv.yml
Include linked issues from "development" field in PR page
1 parent 7eb0ec4 commit 892a336

File tree

1 file changed

+100
-13
lines changed

1 file changed

+100
-13
lines changed

.github/workflows/pull_requests_to_csv.yml

Lines changed: 100 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ on:
77
workflow_dispatch:
88
schedule:
99
- cron: '0 0 * * *' # Runs daily at midnight
10-
# pull_request:
11-
# types: [opened, closed, reopened]
12-
# branches:
13-
# - n2020h-issues-to-csv
10+
1411
jobs:
1512
list-pull-requests:
1613
runs-on: ubuntu-latest
@@ -20,12 +17,12 @@ jobs:
2017
- name: Checkout repository
2118
uses: actions/checkout@v3
2219

23-
###------------------------------------------------------#######
2420
# Set up Node.js to use jq command
2521
- name: Set up Node.js
2622
uses: actions/setup-node@v3
2723
with:
2824
node-version: '20'
25+
2926
# Fetch pull requests data and save it to pulls.json
3027
- name: Fetch pull requests data
3128
env:
@@ -36,15 +33,22 @@ jobs:
3633
"https://api.github.com/repos/${{ github.repository }}/pulls?state=all&per_page=100" \
3734
-o pulls.json
3835
39-
# Check the content of pulls.json for debugging
40-
- name: Display pulls.json content
41-
run: cat pulls.json
36+
# Fetch linked issues for each pull request and save to timeline.json
37+
- name: Fetch linked issues for each PR
38+
env:
39+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40+
run: |
41+
jq -r '.[].number' pulls.json | while read pr; do \
42+
curl -H "Authorization: token $GITHUB_TOKEN" \
43+
-H "Accept: application/vnd.github.v3+json" \
44+
"https://api.github.com/repos/${{ github.repository }}/issues/$pr/timeline?per_page=100" \
45+
-o "timeline_$pr.json"; \
46+
done
4247
43-
# Generate pull requests CSV
44-
# (.body | capture_all("#(?<number>\\d+)"; "g") | join(","))
48+
# Generate pull requests CSV including linked issues
4549
- name: Generate pull requests CSV
4650
run: |
47-
echo "PR Number,Title,Description,Author,State,Number of Commits,Number of Files Changed,Labels,Assignees,Reviewers, Linked Issues" > pull_requests.csv
51+
echo "PR Number,Title,Description,Author,State,Number of Commits,Number of Files Changed,Labels,Assignees,Reviewers,Linked Issues" > pull_requests.csv
4852
jq -r '.[] | select(.user.login != "dependabot[bot]") | [
4953
.number,
5054
.title,
@@ -56,8 +60,14 @@ jobs:
5660
(.labels | map(.name) | join(",")),
5761
(.assignees | map(.login) | join(",")),
5862
(.requested_reviewers | map(.login) | join(",")),
59-
(if .body != null then .body | gsub("#";" ") | split(" ") | map(select(startswith("issue_number"))) | join(",") else "" end)
60-
] | @csv' pulls.json >> pull_requests.csv
63+
(if .number as $pr | .body != null then
64+
(input_filename | sub("timeline_";"") | sub(".json";"")) as $pr_number |
65+
(try input | .[] | select(.event == "cross-referenced" and .source.issue) |
66+
.source.issue.number | tostring + ": " + .source.issue.title | join(", "))
67+
else
68+
""
69+
end)
70+
] | @csv' pulls.json timeline_*.json >> pull_requests.csv
6171
6272
# Check the content of pull_requests.csv for debugging
6373
- name: Display pull_requests.csv content
@@ -75,6 +85,83 @@ jobs:
7585
env:
7686
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7787

88+
##------------------------------------------##
89+
# name: List Pull Requests and Output as CSV
90+
91+
# on:
92+
# push:
93+
# branches:
94+
# - n2020h-issues-to-csv
95+
# workflow_dispatch:
96+
# schedule:
97+
# - cron: '0 0 * * *' # Runs daily at midnight
98+
# # pull_request:
99+
# # types: [opened, closed, reopened]
100+
# # branches:
101+
# # - n2020h-issues-to-csv
102+
# jobs:
103+
# list-pull-requests:
104+
# runs-on: ubuntu-latest
105+
106+
# steps:
107+
# # Checkout the repository to access any scripts or tools you might need
108+
# - name: Checkout repository
109+
# uses: actions/checkout@v3
110+
111+
# # Set up Node.js to use jq command
112+
# - name: Set up Node.js
113+
# uses: actions/setup-node@v3
114+
# with:
115+
# node-version: '20'
116+
# # Fetch pull requests data and save it to pulls.json
117+
# - name: Fetch pull requests data
118+
# env:
119+
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
120+
# run: |
121+
# curl -H "Authorization: token $GITHUB_TOKEN" \
122+
# -H "Accept: application/vnd.github.v3+json" \
123+
# "https://api.github.com/repos/${{ github.repository }}/pulls?state=all&per_page=100" \
124+
# -o pulls.json
125+
126+
# # Check the content of pulls.json for debugging
127+
# - name: Display pulls.json content
128+
# run: cat pulls.json
129+
130+
# # Generate pull requests CSV
131+
# # (.body | capture_all("#(?<number>\\d+)"; "g") | join(","))
132+
# - name: Generate pull requests CSV
133+
# run: |
134+
# echo "PR Number,Title,Description,Author,State,Number of Commits,Number of Files Changed,Labels,Assignees,Reviewers, Linked Issues" > pull_requests.csv
135+
# jq -r '.[] | select(.user.login != "dependabot[bot]") | [
136+
# .number,
137+
# .title,
138+
# .body,
139+
# .user.login,
140+
# .state,
141+
# .commits,
142+
# .changed_files,
143+
# (.labels | map(.name) | join(",")),
144+
# (.assignees | map(.login) | join(",")),
145+
# (.requested_reviewers | map(.login) | join(",")),
146+
# (if .body != null then .body | gsub("#";" ") | split(" ") | map(select(startswith("issue_number"))) | join(",") else "" end)
147+
# ] | @csv' pulls.json >> pull_requests.csv
148+
149+
# # Check the content of pull_requests.csv for debugging
150+
# - name: Display pull_requests.csv content
151+
# run: cat pull_requests.csv
152+
153+
# # Commit and push the generated CSV to the repository
154+
# - name: Commit and push CSV
155+
# run: |
156+
# git config user.name "Automated"
157+
# git config user.email "[email protected]"
158+
# git add -f pull_requests.csv
159+
# timestamp=$(date -u)
160+
# git commit -m "Latest pull requests data: ${timestamp}" || exit 0
161+
# git push --force origin HEAD:refs/heads/n2020h-issues-to-csv
162+
# env:
163+
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
164+
78165
####-------------------------------------------------#######
79166

80167
# # Generate pull requests CSV

0 commit comments

Comments
 (0)