From 4a2114c59837225b73fba5e8ba769f180274c0bb Mon Sep 17 00:00:00 2001 From: Haimantika Mitra Date: Wed, 3 Apr 2024 19:52:44 +0530 Subject: [PATCH 1/3] Added logic to check if a contributor has already contributed to good first issue --- README.md | 1 + action.yml | 31 ++++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index faad6a8..2083fa8 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ This GitHub Action lets a prospective contributor assign themselves to an issue, - `blockingLabels`
A comma-separated list of labels that will prevent the action from running if they are present on the issue. - `blockingLabelsMessage`
The message to display to the user if the issue has a blocking label. - `trigger`
The string that take action will search for in the comment body to activate the action. +- `recurringContributorMessage`
The message to display to the user if they have already contributed to a good first issue. ## Setup diff --git a/action.yml b/action.yml index b643cbb..ba3f450 100644 --- a/action.yml +++ b/action.yml @@ -25,6 +25,11 @@ inputs: required: false default: 'The issue you are trying to assign to yourself is blocked by a one or more labels on the issue.' + recurringContributorMessage: + description: 'Message to contributors who have already contributed to a good first issue' + required: false + default: 'Thanks for your interest in this issue. It looks like this is a good first issue, and you've already contributed to the codebase. Let us leave this issue for a newcomer to the project,but please take a look at our other open issues if you would still like to contribute.' + trigger: description: 'The string that triggers the action' required: false @@ -37,6 +42,18 @@ runs: using: "composite" steps: - run: | + check_if_contributed_to_good_first_issue() { + local assignee="$1" + local response=$(curl -s -H "Authorization: token $GITHUB_PAT" "https://api.github.com/search/issues?q=is:pr+author:$assignee+label:\"good first issue\"") + local total_count=$(echo "$response" | jq -r '.total_count') + + if [ "$total_count" -gt 0 ]; then + echo "true" + else + echo "false" + fi + } + BODY="$(jq '.comment.body' $GITHUB_EVENT_PATH)" ISSUE_NUMBER="$(jq '.issue.number' $GITHUB_EVENT_PATH)" LOGIN="$(jq '.comment.user.login' $GITHUB_EVENT_PATH | tr -d \")" @@ -45,6 +62,7 @@ runs: ISSUE_LABELS="$(jq -r '.issue.labels[].name' $GITHUB_EVENT_PATH)" ISSUE_LABELS=$(echo "$ISSUE_LABELS" | jq -n --arg str "$ISSUE_LABELS" '$str | split("\n")') ISSUE_CURRENTLY_ASSIGNED=`echo $ISSUE_JSON | jq '.assignees | length == 0'` + ASSIGNEES="$(jq -r '.issue.assignees[].login' "$GITHUB_EVENT_PATH")" if [[ $BODY == *"$INPUT_TRIGGER"* ]]; then if [[ "$ISSUE_CURRENTLY_ASSIGNED" == true ]]; then @@ -85,7 +103,17 @@ runs: curl -X POST -H "Authorization: bearer $GITHUB_PAT" --data @payload.json https://api.github.com/repos/$REPO/issues/$ISSUE_NUMBER/comments fi fi - fi + # Check if the user has already contributed to a good first issue + for ASSIGN in $ASSIGNEES; do + HAS_CONTRIBUTED=$(check_if_contributed_to_good_first_issue "$ASSIGN") + if [ "$HAS_CONTRIBUTED" = "true" ]; then + echo "Assignee $ASSIGN has already contributed to a good first issue." + echo "Responding with RECURRING_CONTRIBUTOR_MESSAGE..." + echo "$RECURRING_CONTRIBUTOR_MESSAGE" + break + fi +done + shell: bash env: INPUT_MESSAGE: "${{ inputs.message }}" @@ -93,4 +121,5 @@ runs: BLOCKING_LABELS_MESSAGE: "${{ inputs.blockingLabelsMessage }}" INPUT_TRIGGER: "${{ inputs.trigger }}" ISSUE_CURRENTLY_ASSIGNED_MESSAGE: "${{ inputs.issueCurrentlyAssignedMessage }}" + RECURRING_CONTRIBUTOR_MESSAGE: "${{ inputs.recurringContributorMessage }}" GITHUB_PAT: "${{ inputs.token }}" From d6962474ea4b10d94171227ec8415ca385ab31c9 Mon Sep 17 00:00:00 2001 From: Haimantika Mitra Date: Thu, 4 Apr 2024 00:18:12 +0530 Subject: [PATCH 2/3] Made linting changes --- action.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index ba3f450..3a9afa0 100644 --- a/action.yml +++ b/action.yml @@ -28,7 +28,7 @@ inputs: recurringContributorMessage: description: 'Message to contributors who have already contributed to a good first issue' required: false - default: 'Thanks for your interest in this issue. It looks like this is a good first issue, and you've already contributed to the codebase. Let us leave this issue for a newcomer to the project,but please take a look at our other open issues if you would still like to contribute.' + default: 'Thanks for your interest in this issue. It looks like this is a good first issue, and you have already contributed to the codebase. Let us leave this issue for a newcomer to the project,but please take a look at our other open issues if you would still like to contribute.' trigger: description: 'The string that triggers the action' @@ -111,8 +111,8 @@ runs: echo "Responding with RECURRING_CONTRIBUTOR_MESSAGE..." echo "$RECURRING_CONTRIBUTOR_MESSAGE" break - fi -done + fi + done shell: bash env: From cb2668b085d0aa175e00f566903bc1d0910ca5ec Mon Sep 17 00:00:00 2001 From: Haimantika Mitra Date: Mon, 15 Apr 2024 20:38:14 +0530 Subject: [PATCH 3/3] changed logic --- action.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/action.yml b/action.yml index 3a9afa0..260713e 100644 --- a/action.yml +++ b/action.yml @@ -26,7 +26,7 @@ inputs: default: 'The issue you are trying to assign to yourself is blocked by a one or more labels on the issue.' recurringContributorMessage: - description: 'Message to contributors who have already contributed to a good first issue' + description: 'Message to contributors who have already contributed to the project.' required: false default: 'Thanks for your interest in this issue. It looks like this is a good first issue, and you have already contributed to the codebase. Let us leave this issue for a newcomer to the project,but please take a look at our other open issues if you would still like to contribute.' @@ -42,9 +42,9 @@ runs: using: "composite" steps: - run: | - check_if_contributed_to_good_first_issue() { + check_if_contributed_to_project() { local assignee="$1" - local response=$(curl -s -H "Authorization: token $GITHUB_PAT" "https://api.github.com/search/issues?q=is:pr+author:$assignee+label:\"good first issue\"") + local response=$(curl -s -H "Authorization: token $GITHUB_PAT" "https://api.github.com/search/issues?q=is:pr+author:$assignee") local total_count=$(echo "$response" | jq -r '.total_count') if [ "$total_count" -gt 0 ]; then @@ -105,9 +105,9 @@ runs: fi # Check if the user has already contributed to a good first issue for ASSIGN in $ASSIGNEES; do - HAS_CONTRIBUTED=$(check_if_contributed_to_good_first_issue "$ASSIGN") + HAS_CONTRIBUTED=$(check_if_contributed_to_project "$ASSIGN") if [ "$HAS_CONTRIBUTED" = "true" ]; then - echo "Assignee $ASSIGN has already contributed to a good first issue." + echo "Assignee $ASSIGN has already contributed to the project." echo "Responding with RECURRING_CONTRIBUTOR_MESSAGE..." echo "$RECURRING_CONTRIBUTOR_MESSAGE" break