-
Notifications
You must be signed in to change notification settings - Fork 5
/
pull_request.sh
executable file
Β·167 lines (148 loc) Β· 4.13 KB
/
pull_request.sh
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/env bash
source "base_api.sh"
source "utils.sh"
function list_prs() {
local -r TOKEN="$1"
local -r OWNER="$2"
local -r REPO="$3"
base_api::get "$TOKEN" "repos/$OWNER/$REPO/pulls"
}
function get_pr() {
local -r TOKEN="$1"
local -r OWNER="$2"
local -r REPO="$3"
local -r PR_NUM="$4"
base_api::get "$TOKEN" "repos/$OWNER/$REPO/pulls/$PR_NUM"
}
function get_pr_added_lines() {
local -r TOKEN="$1"
local -r OWNER="$2"
local -r REPO="$3"
local -r PR_NUM="$4"
pr=$(get_pr "$TOKEN" "$OWNER" "$REPO" "$PR_NUM")
echo "$pr" | jq '.additions'
}
function get_pr_deleted_lines() {
local -r TOKEN="$1"
local -r OWNER="$2"
local -r REPO="$3"
local -r PR_NUM="$4"
pr=$(get_pr "$TOKEN" "$OWNER" "$REPO" "$PR_NUM")
echo "$pr" | jq '.deletions'
}
function list_commits() {
local -r TOKEN="$1"
local -r OWNER="$2"
local -r REPO="$3"
local -r PR_NUM="$4"
base_api::get "$TOKEN" "repos/$OWNER/$REPO/pulls/$PR_NUM/commits"
}
function list_commits_message_only() {
local -r TOKEN="$1"
local -r OWNER="$2"
local -r REPO="$3"
local -r PR_NUM="$4"
body=$(base_api::get "$TOKEN" "repos/$OWNER/$REPO/pulls/$PR_NUM/commits")
echo "$body" | jq -r '.[] | .commit.message'
}
function list_commits_files() {
local -r TOKEN="$1"
local -r OWNER="$2"
local -r REPO="$3"
local -r PR_NUM="$4"
body=$(base_api::get "$TOKEN" "repos/$OWNER/$REPO/pulls/$PR_NUM/files")
echo "$body"
}
function list_commits_files_name_only() {
local -r TOKEN="$1"
local -r OWNER="$2"
local -r REPO="$3"
local -r PR_NUM="$4"
body=$(base_api::get "$TOKEN" "repos/$OWNER/$REPO/pulls/$PR_NUM/files")
echo "$body" | jq -r '.[] | .filename'
}
function list_commits_files_added_name_only() {
local -r TOKEN="$1"
local -r OWNER="$2"
local -r REPO="$3"
local -r PR_NUM="$4"
body=$(base_api::get "$TOKEN" "repos/$OWNER/$REPO/pulls/$PR_NUM/files")
echo "$body" | jq -r 'map(select(.status != "removed")) | .[].filename'
}
function prs_count() {
local -r TOKEN="$1"
local -r OWNER="$2"
local -r REPO="$3"
body=$(base_api::get "$TOKEN" "repos/$OWNER/$REPO/pulls")
echo "$body" | jq '. | length'
}
function get_pr_author() {
local -r TOKEN="$1"
local -r OWNER="$2"
local -r REPO="$3"
local -r PR_NUM="$4"
body=$(base_api::get "$TOKEN" "repos/$OWNER/$REPO/pulls/$PR_NUM")
echo "$body" | jq -r '.user.login'
}
function get_pr_changed_files_count() {
local -r TOKEN="$1"
local -r OWNER="$2"
local -r REPO="$3"
local -r PR_NUM="$4"
body=$(base_api::get "$TOKEN" "repos/$OWNER/$REPO/pulls/$PR_NUM")
echo "$body" | jq '.changed_files'
}
function comment_on_pr() {
local -r TOKEN="$1"
local -r OWNER="$2"
local -r REPO="$3"
local -r PR_NUM="$4"
local -r PAYLOAD="$5"
# payload should be: {"body": <message>}
res=$(base_api::post "$TOKEN" "repos/$OWNER/$REPO/issues/$PR_NUM/comments" "$PAYLOAD")
echo "$res" | jq '.body'
}
function close_pr() {
local -r TOKEN="$1"
local -r OWNER="$2"
local -r REPO="$3"
local -r PR_NUM="$4"
local -r PAYLOAD="$5"
# payload should be: {"state": "close", "body": <message>}
base_api::patch "$TOKEN" "repos/$OWNER/$REPO/pulls/$PR_NUM" "$PAYLOAD"
}
function get_pr_labels() {
local -r TOKEN="$1"
local -r OWNER="$2"
local -r REPO="$3"
local -r PR_NUM="$4"
body=$(base_api::get "$TOKEN" "repos/$OWNER/$REPO/issues/$PR_NUM")
echo "$body" | jq -r '.labels[].name'
}
function add_pr_label() {
local -r TOKEN="$1"
local -r OWNER="$2"
local -r REPO="$3"
local -r PR_NUM="$4"
local -r PAYLOAD="$5"
# payload should be: {"labels": ["label2", "label2"]}
base_api::post "$TOKEN" "repos/$OWNER/$REPO/issues/$PR_NUM/labels" "$PAYLOAD"
}
function remove_pr_label() {
local -r TOKEN="$1"
local -r OWNER="$2"
local -r REPO="$3"
local -r PR_NUM="$4"
local -r PAYLOAD="$5"
# payload should be the name of the label
base_api::delete "$TOKEN" "repos/$OWNER/$REPO/issues/$PR_NUM/labels/$PAYLOAD"
}
function get_base_branch() {
local -r TOKEN="$1"
local -r OWNER="$2"
local -r REPO="$3"
local -r PR_NUM="$4"
# payload should be the name of the label
body=$(base_api::get "$TOKEN" "repos/$OWNER/$REPO/pulls/$PR_NUM")
echo "$body" | jq -r '.head.ref'
}