-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresult_issue_generator.sh
executable file
·130 lines (112 loc) · 2.64 KB
/
result_issue_generator.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
#!/bin/bash
#
# requires:
# bash
#
set -e
set -o pipefail
#set -x
. ./config
. ./functions
function result_issue_new() {
local mon_u=$1 fri_u=$2 assignee=$3
local title body
title="作業実績 (${assignee}): "$(date_range "${mon_u}" "${fri_u}")
body=$(build_body ${mon_u} ${fri_u})
curl \
-i \
-X POST \
-H "Authorization: token ${GITHUB_TOKEN}" \
--data @- \
${BASE_URI}/repos/${OWNER}/${REPO}/issues <<-EOS
{
"title": "${title}",
"body": "${body}",
"assignee": "${assignee}",
"milestone": "${MILESTONE_NUMBER}"
}
EOS
}
function result_issue_new_debug() {
local mon_u=$1 fri_u=$2 assignee=$3
local title body
title="作業実績 (${assignee}): "$(date_range "${mon_u}" "${fri_u}")
body=$(build_body ${mon_u} ${fri_u})
cat <<-EOS
${BASE_URI}/repos/${OWNER}/${REPO}/issues <<-EOS
{
"title": "${title}",
"body": "${body}",
"assignee": "${assignee}",
"milestone": "${MILESTONE_NUMBER}"
}
EOS
}
function u_days_fmt() {
local days=${1}
date -d "${days} days" +'%m/%d(%a)'
}
function date_range() {
local begin_date=${1} end_date=${2}
echo "$(u_days_fmt ${begin_date})".."$(u_days_fmt ${end_date})"
}
function build_body() {
local mon_u=$1 fri_u=$2
local body
body="#### The plan for this week"
for ((d=${mon_u}; d <= ${fri_u}; d++))
do
body="${body}\n#### $(u_days_fmt $d)\n"
done
echo ${body}
}
### 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
if [ "$WEEK" = "this" ]; then
mon_u="$((1 - ${cur_u}))"
else
mon_u="$((8 - ${cur_u}))"
fi
fri_u="$((${mon_u} + 4))"
# result issue cration
for m in ${MEMBERS}
do
if [ "$DEBUG" = "true" ]; then
result_issue_new_debug ${mon_u} ${fri_u} ${m}
else
result_issue_new ${mon_u} ${fri_u} ${m}
fi
done