@@ -8,18 +8,21 @@ ORGANIZATION=
8
8
OUTPUTFILE=
9
9
PRESERVE=false
10
10
TEAM=
11
+ USERS=()
11
12
12
13
__USAGE="
13
14
Generate montage from GitHub user avatars.
14
15
15
16
USAGE
16
- $( basename $0 ) [options] <organization>
17
- $( basename $0 ) [options] <organization>/<team>
17
+ gh montage [options] <organization>
18
+ gh montage [options] <organization>/<team>
19
+ gh montage [options] <path/to/username file>
18
20
19
21
FLAGS
20
22
-a, --avatar-pixels <integer> Size of GitHub avatar icons in pixels; default '$AVATARPIXELS '
21
23
-d, --debug Enable debugging
22
24
-f, --force Whether to overwrite output file if it exists
25
+ -h, --help Displays help usage
23
26
-m, --montage-width <integer> Width of GitHub montage in number of avatar icons; default '$MONTAGEWIDTH '
24
27
-o, --output-file <output-file> Name of GitHub montage file to generate, without '.png' extension
25
28
-p, --preserve Preserve temporary directory containing data
@@ -92,6 +95,18 @@ elif [[ "$1" == *"/"* ]]; then
92
95
if [ -z " ${OUTPUTFILE} " ]; then
93
96
OUTPUTFILE=" $ORGANIZATION -$TEAM -$AVATARPIXELS .png"
94
97
fi
98
+ elif [ -f " $1 " ]; then
99
+ # If argument is valid file, read usernames from file
100
+ USERS_FILE=" $1 "
101
+ printf " Reading users from file: %s\n" " $USERS_FILE "
102
+
103
+ while IFS= read -r USER; do
104
+ USERS+=(" $USER " )
105
+ done < " $USERS_FILE "
106
+
107
+ if [ -z " ${OUTPUTFILE} " ]; then
108
+ OUTPUTFILE=" $( basename " " $USERS_FILE " " ) .png"
109
+ fi
95
110
else
96
111
ORGANIZATION=" $1 "
97
112
@@ -121,64 +136,62 @@ if ! $PRESERVE; then
121
136
trap ' rm -rf -- "$TMPDIR"' EXIT
122
137
fi
123
138
124
- # Determine how many GitHub user
125
- if [ -z " ${TEAM} " ]; then
126
- QUERY='
127
- query CountOrgAvatars($login: String!) {
128
- organization(login: $login) {
129
- membersWithRole {
130
- totalCount
139
+ # Generate script around retrieving user avatars and generating montage as necessary
140
+ echo " Generating GitHub montage script: $TMPFILE "
141
+
142
+ if [ -n " ${USERS} " ]; then
143
+ echo " GitHub avatars found: ${# USERS[@]} "
144
+
145
+ for USER in " ${USERS[@]} " ; do
146
+ QUERY='
147
+ query GetUser($login: String!) {
148
+ user(login: $login) {
149
+ avatarUrl
150
+ databaseId
131
151
}
132
- }
133
- }'
152
+ }'
134
153
135
- JQ=' .data.organization.membersWithRole.totalCount'
154
+ TEMPLATE="
155
+ curl -s \" {{ .data.user.avatarUrl }}\" --output $TMPDIR /{{ .data.user.databaseId }}.jpg"
156
+
157
+ gh api graphql -f query=" ${QUERY} " -F login=" $USER " --template=" ${TEMPLATE} " >> $TMPFILE
158
+ done
136
159
else
137
- QUERY= '
138
- query CountOrgTeamAvatars($login: String!, $slug: String!) {
139
- organization( login: $login ) {
140
- team(slug : $slug ) {
141
- members {
160
+ if [ -z " ${TEAM} " ] ; then
161
+ QUERY= '
162
+ query CountOrgAvatars($ login: String! ) {
163
+ organization(login : $login ) {
164
+ membersWithRole {
142
165
totalCount
143
166
}
144
167
}
145
- }
146
- }'
147
-
148
- JQ=' .data.organization.team.members.totalCount'
149
- fi
150
-
151
- AVATARCOUNT=$( gh api graphql -f query=" ${QUERY} " -F login=" $ORGANIZATION " -F slug=" $TEAM " --jq " $JQ " )
152
- echo " GitHub avatars found: $AVATARCOUNT "
153
-
154
- # Generate script commands to download GitHub user avatar images sized accordingly
155
- if [ -z " ${TEAM} " ]; then
156
- QUERY='
157
- query GetOrgAvatars($login: String!, $endCursor: String) {
158
- organization(login: $login) {
159
- membersWithRole(first: 100, after: $endCursor) {
160
- pageInfo {
161
- endCursor
162
- hasNextPage
163
- }
164
- nodes {
165
- avatarUrl
166
- databaseId
168
+ }'
169
+
170
+ JQ=' .data.organization.membersWithRole.totalCount'
171
+ else
172
+ QUERY='
173
+ query CountOrgTeamAvatars($login: String!, $slug: String!) {
174
+ organization(login: $login) {
175
+ team(slug: $slug) {
176
+ members {
177
+ totalCount
178
+ }
167
179
}
168
180
}
169
- }
170
- }'
181
+ }'
171
182
172
- TEMPLATE="
173
- {{ range .data.organization.membersWithRole.nodes }}
174
- curl -s \" {{ .avatarUrl }}\" --output $TMPDIR /{{ .databaseId }}.jpg
175
- {{ end }}"
176
- else
177
- QUERY='
178
- query GetOrgTeamAvatars($login: String!, $slug: String!, $endCursor: String) {
179
- organization(login: $login) {
180
- team(slug: $slug) {
181
- members(first: 100, after: $endCursor) {
183
+ JQ=' .data.organization.team.members.totalCount'
184
+ fi
185
+
186
+ AVATARCOUNT=$( gh api graphql -f query=" ${QUERY} " -F login=" $ORGANIZATION " -F slug=" $TEAM " --jq " $JQ " )
187
+ echo " GitHub avatars found: $AVATARCOUNT "
188
+
189
+ # Generate script commands to download GitHub user avatar images sized accordingly
190
+ if [ -z " ${TEAM} " ]; then
191
+ QUERY='
192
+ query GetOrgAvatars($login: String!, $endCursor: String) {
193
+ organization(login: $login) {
194
+ membersWithRole(first: 100, after: $endCursor) {
182
195
pageInfo {
183
196
endCursor
184
197
hasNextPage
@@ -189,17 +202,41 @@ else
189
202
}
190
203
}
191
204
}
192
- }
193
- }'
205
+ }'
206
+
207
+ TEMPLATE="
208
+ {{ range .data.organization.membersWithRole.nodes }}
209
+ curl -s \" {{ .avatarUrl }}\" --output $TMPDIR /{{ .databaseId }}.jpg
210
+ {{ end }}"
211
+
212
+ else
213
+ QUERY='
214
+ query GetOrgTeamAvatars($login: String!, $slug: String!, $endCursor: String) {
215
+ organization(login: $login) {
216
+ team(slug: $slug) {
217
+ members(first: 100, after: $endCursor) {
218
+ pageInfo {
219
+ endCursor
220
+ hasNextPage
221
+ }
222
+ nodes {
223
+ avatarUrl
224
+ databaseId
225
+ }
226
+ }
227
+ }
228
+ }
229
+ }'
194
230
195
- TEMPLATE="
231
+ TEMPLATE="
196
232
{{ range .data.organization.team.members.nodes }}
197
233
curl -s \" {{ .avatarUrl }}\" --output $TMPDIR /{{ .databaseId }}.jpg
198
234
{{ end }}"
199
- fi
200
235
201
- echo " Generating GitHub montage script: $TMPFILE "
202
- gh api graphql -f query=" ${QUERY} " -F login=" $ORGANIZATION " -F slug=" $TEAM " --paginate --template=" ${TEMPLATE} " >> $TMPFILE
236
+ fi
237
+
238
+ gh api graphql -f query=" ${QUERY} " -F login=" $ORGANIZATION " -F slug=" $TEAM " --paginate --template=" ${TEMPLATE} " >> $TMPFILE
239
+ fi
203
240
204
241
# Conclude script creation with commands to generate montage and execute
205
242
cat << EOF >> $TMPFILE
0 commit comments