7
7
workflow_dispatch :
8
8
schedule :
9
9
- cron : ' 0 0 * * *' # Runs daily at midnight
10
- # pull_request:
11
- # types: [opened, closed, reopened]
12
- # branches:
13
- # - n2020h-issues-to-csv
10
+
14
11
jobs :
15
12
list-pull-requests :
16
13
runs-on : ubuntu-latest
@@ -20,12 +17,12 @@ jobs:
20
17
- name : Checkout repository
21
18
uses : actions/checkout@v3
22
19
23
- # ##------------------------------------------------------#######
24
20
# Set up Node.js to use jq command
25
21
- name : Set up Node.js
26
22
uses : actions/setup-node@v3
27
23
with :
28
24
node-version : ' 20'
25
+
29
26
# Fetch pull requests data and save it to pulls.json
30
27
- name : Fetch pull requests data
31
28
env :
@@ -36,15 +33,22 @@ jobs:
36
33
"https://api.github.com/repos/${{ github.repository }}/pulls?state=all&per_page=100" \
37
34
-o pulls.json
38
35
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
42
47
43
- # Generate pull requests CSV
44
- # (.body | capture_all("#(?<number>\\d+)"; "g") | join(","))
48
+ # Generate pull requests CSV including linked issues
45
49
- name : Generate pull requests CSV
46
50
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
48
52
jq -r '.[] | select(.user.login != "dependabot[bot]") | [
49
53
.number,
50
54
.title,
56
60
(.labels | map(.name) | join(",")),
57
61
(.assignees | map(.login) | join(",")),
58
62
(.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
61
71
62
72
# Check the content of pull_requests.csv for debugging
63
73
- name : Display pull_requests.csv content
75
85
env :
76
86
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
77
87
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
+
78
165
# ###-------------------------------------------------#######
79
166
80
167
# # Generate pull requests CSV
0 commit comments