-
Notifications
You must be signed in to change notification settings - Fork 3
/
pull_issues.sh
executable file
·100 lines (86 loc) · 3.19 KB
/
pull_issues.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
#!/bin/bash
display_usage() {
echo "This script will save the ID, and labels of the Brainhack Global projects for the given event.\n"
echo "Usage:"
echo "\tsh pull_issues.sh OUTPUT EVENT (REPO)\n"
echo "Arguments:\n"
echo "\tOUTPUT [required]: Path to store the output file. It can also be a filename. It must have the '.tsv' extension.\n"
echo "\tEVENT [required]: Label of the Brainhack Global event to pull project data from. It must start by 'bhg:'. If projects from all events are desired, use 'bhg:global'.\n"
echo "\tREPO [optional]: Path to global 2020 repository. Usefule if you do not want to clone the repository again."
echo "\tIf this argument is not given, the script will clone the repository and delete it once the script finishes.\n"
echo "Help:\n"
echo "\tYou can display this help message using the '-h' and '--help' flags as in:\n"
echo "\t'pull_issues.sh -h' or 'pull_issues.sh --help'"
}
# If no arguments are supplied, display usage.
if [ $# -le 1 ]
then
display_usage
exit 1
fi
# Check whether user supplied -h or --help . If yes, display usage.
if [[ ( $* == "--help") || $* == "-h" ]]
then
display_usage
exit 0
fi
# Filename of output file (it can include the path).
OUTFILE=$1
# Event label.
EVENT=$2
# Path to the repository. It can be empty
REPOPATH=$3
# If REPOPATH is given then move into that directory and if it is not given then
# clone Brainhack Global 2020 repository to get project info and move into directory.
if [ $# -eq 3 ]
then
echo "Moving into ${REPOPATH}"
DIR_EXISTS=true
cd ${REPOPATH}
else
echo "The global2020 directory could not be found..."
DIR_EXISTS=false
git clone https://github.com/brainhackorg/global2020
cd global2020
fi
# Get ID of projects on GitHub issues.
if [[ ${EVENT} == "bhg:global" ]]
then
ISSUE_ID_LIST=$(gh issue list -L 1000 | awk '{print $1}')
else
ISSUE_ID_LIST=$(gh issue list -L 1000 -l "${EVENT}"| awk '{print $1}')
fi
# Create output file and add header.
echo "ID LABELS \n" > ${OUTFILE}
echo "Pulling data from project issues... "
# Loop throuh found issues.
for ISSUE_ID in $ISSUE_ID_LIST
do
# Get project labels.
LABELS_LIST=$(gh issue view "${ISSUE_ID}" | grep 'labels:')
LABELS_LIST=${LABELS_LIST#"labels:"}
# Only save the issue if the issue has the project and (web_ready or published) labels.
if [[ ${LABELS_LIST} == *project* ]] && [[ ${LABELS_LIST} == *status:web_ready* || ${LABELS_LIST} == *status:published* ]]
then
# Save ID, title and labels to output file.
echo "${ISSUE_ID##*( )} ${LABELS_LIST##*( )}\n" >> ${OUTFILE}
fi
done
# Leave directory.
cd ..
# Check if filename has a slash (path). Move the file one directory up if it's just a filename.
if [[ "${OUTFILE}" != *\/* ]] || [[ "${OUTFILE}" != *\\* ]]
then
echo "An absolute path for the output file was not provided."
echo "Moving output file one directory up..."
mv global2020/${OUTFILE} .
CURRENT_DIR=$(pwd)
OUTFILE=$(echo "${CURRENT_DIR}/${OUTFILE}")
fi
# Do not remove directory if it already existed.
if ! ${DIR_EXISTS}
then
echo "Removing cloned repository..."
rm -rf global2020
fi
echo "Projects data saved in ${OUTFILE}"