|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +set -ex |
| 4 | + |
| 5 | +ORG=nodejs |
| 6 | +REPO=collaborators |
| 7 | + |
| 8 | +prepare_collaborator_nomination() { |
| 9 | + HANDLE="$1" |
| 10 | + |
| 11 | + [ -n "$HANDLE" ] || { |
| 12 | + echo "Missing handle" >&2 |
| 13 | + return 1 |
| 14 | + } |
| 15 | + |
| 16 | + BODY_FILE=$(mktemp) |
| 17 | + cat -> "$BODY_FILE" <<EOF |
| 18 | +<!-- Consider writing a small intro on the contributor and their contributions --> |
| 19 | +
|
| 20 | +* Commits in the nodejs/node repository: https://github.com/nodejs/node/commits?author=$HANDLE |
| 21 | +* Pull requests and issues opened in the nodejs/node repository: https://github.com/nodejs/node/issues?q=author:$HANDLE |
| 22 | +* Comments on pull requests and issues in the nodejs/node repository: https://github.com/nodejs/node/issues?q=commenter:$HANDLE |
| 23 | +* Reviews on pull requests in the nodejs/node repository: https://github.com/nodejs/node/pulls?q=reviewed-by:$HANDLE |
| 24 | +* Pull requests and issues opened throughout the Node.js organization: https://github.com/search?q=author:$HANDLE+org:$ORG |
| 25 | +* Comments on pull requests and issues throughout the Node.js organization: https://github.com/search?q=commenter:$HANDLE+org:$ORG |
| 26 | +
|
| 27 | +<!-- You can add more item to that lists, such as: --> |
| 28 | +<!-- |
| 29 | +* Help provided to end-users and novice contributors |
| 30 | +* Participation in other projects, teams, and working groups of the Node.js |
| 31 | + organization |
| 32 | +* Other participation in the wider Node.js community |
| 33 | +--> |
| 34 | +EOF |
| 35 | + $EDITOR "$BODY_FILE" |
| 36 | + BODY="$(cat "$BODY_FILE")" |
| 37 | + rm "$BODY_FILE" |
| 38 | + |
| 39 | + [ -n "$BODY" ] || { |
| 40 | + echo "Empty body" >&2 |
| 41 | + return 1 |
| 42 | + } |
| 43 | + |
| 44 | + echo "Getting repo ID and discussion category" >&2 |
| 45 | + REPO_ID_AND_DISCUSSION_CATEGORY_ID="$(gh api graphql -f query=' |
| 46 | + query($owner:String!,$repo:String!){ |
| 47 | + repository(owner:$owner,name:$repo){ |
| 48 | + id |
| 49 | + discussionCategories(first:100){ |
| 50 | + nodes{ id name } |
| 51 | + } |
| 52 | + } |
| 53 | + }' -F owner="$ORG" -F repo="$REPO" --jq '[ |
| 54 | + .data.repository.id, |
| 55 | + (.data.repository.discussionCategories.nodes[] | select(.name=="Collaborator nominations") | .id) |
| 56 | + ] | @tsv')" |
| 57 | + REPO_ID=$(echo "$REPO_ID_AND_DISCUSSION_CATEGORY_ID" | cut -f1) |
| 58 | + [ -n "$REPO_ID" ] || { |
| 59 | + echo "Cannot find repo ID" >&2 |
| 60 | + return 1 |
| 61 | + } |
| 62 | + CATEGORY_ID=$(echo "$REPO_ID_AND_DISCUSSION_CATEGORY_ID" | cut -f2) |
| 63 | + [ -n "$CATEGORY_ID" ] || { |
| 64 | + echo "Missing discussion category ID" >&2 |
| 65 | + return 1 |
| 66 | + } |
| 67 | + |
| 68 | + gh api graphql -f query=' |
| 69 | + mutation($repo: ID!,$cat: ID!,$title: String!,$body: String!){ |
| 70 | + createDiscussion(input: { |
| 71 | + repositoryId: $repo |
| 72 | + categoryId: $cat |
| 73 | + title: $title |
| 74 | + body: $body |
| 75 | + }){ discussion { url } } |
| 76 | + }' \ |
| 77 | + -F repo="$REPO_ID" -F cat="$CATEGORY_ID" -F title="Nominating ${HANDLE}?" -F body="$BODY" |
| 78 | +} |
| 79 | + |
| 80 | +prepare_collaborator_nomination "$1" |
0 commit comments