-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsitdown.sh
executable file
·101 lines (85 loc) · 2.61 KB
/
sitdown.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
#!/bin/bash
#
# query github graphql api with curl
# transform data into suitable format with jq
# output standup notes in markdown format to stdout
read -p "Load variables from .env file? (y/n)" load_env
while true; do
case "${load_env}" in
[Yy])
source ./.env
break
;;
[Nn])
unset TOKEN
unset USERNAME
unset REPO
unset DATE_START
unset DATE_END
COUNT=10
while [[ -z "${TOKEN}" ]]; do
read -sp 'GitHub Personal Access Token ' TOKEN
echo
done
while [[ -z "${USERNAME}" ]]; do
read -p 'GitHub username ' USERNAME
done
while [[ -z "${REPO}" ]]; do
read -p 'Repository name including owner [e.g., octocat/Hello-World] ' REPO
done
while [[ -z "${DATE_START}" ]]; do
read -p 'Start Date in YYYY-MM-DD format (inclusive) ' DATE_START
done
while [[ -z "${DATE_END}" ]]; do
read -p 'End Date in YYYY-MM-DD format (inclusive) ' DATE_END
done
break
;;
*) echo "Enter (y/n)" ;;
esac
done
function query() {
# use space as delimiter for sed because REPO contains slash
local gql=$(
cat $1 | sed \
-e "s \${repo} ${REPO} " \
-e "s \${username} ${USERNAME} " \
-e "s \${date_range} ${DATE_START}..${DATE_END} " \
-e "s \${last} ${COUNT} "
)
# format query to escape double quotes and remove newlines
local query=$(jq -n --arg q "$(echo ${gql} | tr -d '\n')" '{query:$q}')
curl -X POST \
-s \
-H "Authorization: bearer ${TOKEN}" \
-H "Content-Type: application/json" \
-d "$query" \
https://api.github.com/graphql
}
# use jq -r to remove double quotes
authored_issues=$(
query ./queries/authored_issues.gql |
jq -r '.data.search.edges|.[]|.node|"- Opened issue [\(.number)](\(.url)): \(.title)"'
)
merged_pr=$(
query ./queries/merged_pr.gql |
jq -r '.data.search.edges|.[]|.node|"- PR merged [\(.number)](\(.url)): \(.title)"'
)
open_issues=$(
query ./queries/open_issues.gql |
jq -r '.data.search.edges|.[]|.node|"- Issue [\(.number)](\(.url)): \(.title)"'
)
open_pr=$(query ./queries/open_pr.gql |
jq -r '.data.search.edges|.[]|.node|"- PR [\(.number)](\(.url)): \(.title)"')
cat <<EOF
**What did you achieve in the last 24 hours?**:
${merged_pr}
${authored_issues}
**What are your priorities for the next 24 hours?**:
${open_pr}
${open_issues}
**Blockers**:
- not sure if I really do exist or if I'm just a simulation
**Shoutouts**:
- my computer
EOF