-
Notifications
You must be signed in to change notification settings - Fork 63
106 lines (94 loc) · 3.77 KB
/
pr-metrics.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
name: ROI PR metrics
on:
pull_request:
types: [review_requested]
jobs:
record_pr_timestamp:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
outputs:
pr_timestamp: ${{ steps.get_pr_timestamp.outputs.pr_timestamp }}
steps:
- name: Get Current Timestamp for PR
id: get_pr_timestamp
run: |
current_timestamp=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
seconds_since_epoch=$(date -d "${current_timestamp}" +%s)
echo "PR timestamp: ${current_timestamp}"
echo "PR timestamp in seconds: ${seconds_since_epoch}"
echo "::set-output name=pr_timestamp::${seconds_since_epoch}"
get_issue_timestamp:
needs: record_pr_timestamp
runs-on: ubuntu-latest
outputs:
issue_timestamp: ${{ steps.get_issue_timestamp.outputs.issue_timestamp }}
steps:
- name: Checkout the repository
uses: actions/checkout@v2
- name: Checkout Source Branch
run: |
git fetch
echo "Current Branch: $(git branch)"
git checkout ${{github.event.pull_request.head.ref}}
- name: Get Issue Timestamp
id: get_issue_timestamp
working-directory: roiScript
run: | # timestamp: Dunridge, issue #767: 2023-11-14 16:06:02
issue_timestamp=$(cat issue_timestamp.log | awk -F ': ' '{print $2}')
seconds_since_epoch=$(date -d "${issue_timestamp}" +"%s")
echo "Issue timestamp from the first step: ${issue_timestamp}"
echo "Issue timestamp in seconds: ${seconds_since_epoch}"
echo "::set-output name=issue_timestamp::${seconds_since_epoch}"
echo "" > issue_timestamp.log
- name: Commit Timestamp Removal # step + echo "" > issue_timestamp.log -- for clearing the issue_timestamp.log file so that this doesn't run on second reviewer assignment
run: |
git config --global user.email "[email protected]"
git config --global user.name "Dunridge"
git add .
git commit -m "Remove issue timestamp by $GITHUB_ACTOR"
git push https://${{ secrets.GH_TOKEN }}@github.com/${{ github.repository }}.git
calculate_time_difference:
needs:
- record_pr_timestamp
- get_issue_timestamp
runs-on: ubuntu-latest
outputs:
time_diff: ${{ steps.time_difference.outputs.time_diff }}
env:
pr_timestamp_input: ${{needs.record_pr_timestamp.outputs.pr_timestamp}}
issue_timestamp_input: ${{needs.get_issue_timestamp.outputs.issue_timestamp}}
steps:
- name: Calculate Time Difference
id: time_difference
run: |
issue_timestamp=$issue_timestamp_input
echo "Issue timestamp (seconds): ${issue_timestamp}"
pr_timestamp=$pr_timestamp_input
echo "PR timestamp (seconds): ${pr_timestamp}"
time_diff=$((pr_timestamp - issue_timestamp))
echo "Time Difference: ${time_diff}"
echo "::set-output name=time_diff::${time_diff}"
metric:
needs: calculate_time_difference
runs-on: ubuntu-latest
env:
time_diff_input: ${{needs.calculate_time_difference.outputs.time_diff}}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 18 # pick the node version that's compatible with libraries
- name: Output Time Diff
run: |
echo "Time Diff For Output: $time_diff_input"
- name: Install
run: npm install
working-directory: ./roiScript
- name: Run
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
TIME_DIFF: ${{ needs.calculate_time_difference.outputs.time_diff }}
PR_NUMBER: ${{ github.event.number }}
run: node ./roiScript/issue-metrics.mjs