-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresult_issue_closer.sh
executable file
·121 lines (105 loc) · 2.55 KB
/
result_issue_closer.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
#!/bin/bash
#
# requires:
# bash
#
set -e
set -o pipefail
#set -x
. ./config
. ./functions
function result_issue_close() {
local assignee=$1 title_pattern=$2
local issue_number
issue_number=$(get_issue_number ${assignee} "open" ${title_pattern})
if [ -z "${issue_number}" ]; then
echo "Not found issue: ${assignee} ${title_pattern}"
return
fi
curl \
-i \
-X PATCH \
-H "Authorization: token ${GITHUB_TOKEN}" \
--data @- \
${BASE_URI}/repos/${OWNER}/${REPO}/issues/${issue_number} <<-EOS
{
"state": "closed"
}
EOS
}
function result_issue_close_debug() {
local assignee=$1 title_pattern=$2
local issue_number
issue_number=$(get_issue_number ${assignee} "open" ${title_pattern})
if [ -z "${issue_number}" ]; then
echo "Not found issue: ${assignee} ${title_pattern}"
return
fi
echo ${assignee}
echo curl \
-i \
-X PATCH \
-H "Authorization: token ${GITHUB_TOKEN}" \
--data @- \
${BASE_URI}/repos/${OWNER}/${REPO}/issues/${issue_number} <<-EOS
{
"state": "closed"
}
EOS
}
function u_days_fmt() {
local days=${1}
date -d "${days} days" +'%m\/%d\(%a\)'
}
function get_title_pattern() {
local begin_date=${1} end_date=${2}
echo "$(u_days_fmt ${begin_date})"\.\."$(u_days_fmt ${end_date})"
}
### Main ###
# arguments checking
# milestone checking
if [ $# -ne 1 ] && [ $# -ne 4 ] ; then
echo "Error: Few or more arguments."
echo "Usage: $0 GITHUB_TOKEN [OWNER REPO MILESTONE_NAME]"
exit 1
fi
GITHUB_TOKEN=$1
OWNER=${2:-$OWNER}
if [ -z "$OWNER" ]; then
echo "Error: No owner was set."
echo "Usage: $0 GITHUB_TOKEN [OWNER REPO MILESTONE_NAME]"
exit 1
fi
REPO=${3:-$REPO}
if [ -z "$REPO" ]; then
echo "Error: No repo was set."
echo "Usage: $0 GITHUB_TOKEN [OWNER REPO MILESTONE_NAME]"
exit 1
fi
MILESTONE_NAME=${4:-$MILESTONE_NAME}
if [ -z "$MILESTONE_NAME" ]; then
echo "Error: No milestone name was set."
echo "Usage: $0 GITHUB_TOKEN [OWNER REPO MILESTONE_NAME]"
exit 1
fi
MILESTONE_NUMBER=$(get_milestone_number "${MILESTONE_NAME}")
if [ -z "$MILESTONE_NUMBER" ]; then
echo "Error: No milestone was found (${MILESTONE_NAME})."
echo "Usage: $0 GITHUB_TOKEN [OWNER REPO MILESTONE_NAME]"
exit 1
fi
# days params
cur_u=$(date +%u) # 1..7
mon_u="$((-6 - ${cur_u}))"
fri_u="$((${mon_u} + 4))"
# result issue cration
title_pattern=$(get_title_pattern ${mon_u} ${fri_u})
echo $DEBUG
for m in ${MEMBERS}
do
if [ "$DEBUG" = "true" ]; then
result_issue_close_debug ${m} ${title_pattern}
else
result_issue_close ${m} ${title_pattern}
fi
done