-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
Expand file tree
/
Copy pathnominate.sh
More file actions
executable file
·82 lines (71 loc) · 2.61 KB
/
nominate.sh
File metadata and controls
executable file
·82 lines (71 loc) · 2.61 KB
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
#!/bin/sh
set -ex
ORG=nodejs
REPO=collaborators
prepare_collaborator_nomination() {
HANDLE="$1"
[ -n "$HANDLE" ] || {
echo "Missing handle" >&2
return 1
}
BODY_FILE=$(mktemp)
cat -> "$BODY_FILE" <<EOF
<!-- Consider writing a small intro on the contributor and their contributions -->
* Commits in the nodejs/node repository: https://github.com/nodejs/node/commits?author=$HANDLE
* Pull requests and issues opened in the nodejs/node repository: https://github.com/nodejs/node/issues?q=author:$HANDLE
* Comments on pull requests and issues in the nodejs/node repository: https://github.com/nodejs/node/issues?q=commenter:$HANDLE
* Reviews on pull requests in the nodejs/node repository: https://github.com/nodejs/node/pulls?q=reviewed-by:$HANDLE
* Pull requests and issues opened throughout the Node.js organization: https://github.com/search?q=author:$HANDLE+org:$ORG
* Comments on pull requests and issues throughout the Node.js organization: https://github.com/search?q=commenter:$HANDLE+org:$ORG
<!-- You can add more item to that lists, such as: -->
<!--
* Help provided to end-users and novice contributors
* Participation in other projects, teams, and working groups of the Node.js
organization
* Other participation in the wider Node.js community
-->
EOF
${EDITOR:-nano} "$BODY_FILE"
BODY="$(cat "$BODY_FILE")"
rm "$BODY_FILE"
[ -n "$BODY" ] || {
echo "Empty body" >&2
return 1
}
echo "Getting repo ID and discussion category" >&2
# shellcheck disable=SC2016
REPO_ID_AND_DISCUSSION_CATEGORY_ID="$(gh api graphql -f query='
query($owner:String!,$repo:String!){
repository(owner:$owner,name:$repo){
id
discussionCategories(first:100){
nodes{ id name }
}
}
}' -F owner="$ORG" -F repo="$REPO" --jq '[
.data.repository.id,
(.data.repository.discussionCategories.nodes[] | select(.name=="Collaborator nominations") | .id)
] | @tsv')"
REPO_ID=$(echo "$REPO_ID_AND_DISCUSSION_CATEGORY_ID" | cut -f1)
[ -n "$REPO_ID" ] || {
echo "Cannot find repo ID" >&2
return 1
}
CATEGORY_ID=$(echo "$REPO_ID_AND_DISCUSSION_CATEGORY_ID" | cut -f2)
[ -n "$CATEGORY_ID" ] || {
echo "Missing discussion category ID" >&2
return 1
}
# shellcheck disable=SC2016
gh api graphql -f query='
mutation($repo: ID!,$cat: ID!,$title: String!,$body: String!){
createDiscussion(input: {
repositoryId: $repo
categoryId: $cat
title: $title
body: $body
}){ discussion { url } }
}' \
-F repo="$REPO_ID" -F cat="$CATEGORY_ID" -F title="Nominating ${HANDLE}?" -F body="$BODY"
}
prepare_collaborator_nomination "$1"