Skip to content

Commit

Permalink
Fix bugs: (#1825)
Browse files Browse the repository at this point in the history
* Fix bugs:
- addLabelable was adding eeach id insteqad of one at a time
- using functions is not a good idea in bash

* Add exit for no issues found and log issues before mutating state

* Add explicit rate limit check

* Add label if no jira link

* Don't cancel but queue jobs
  • Loading branch information
KevinMind committed May 3, 2024
1 parent 8ff443a commit 89ae676
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/transfer-issues.yml
Expand Up @@ -47,7 +47,7 @@ permissions: write-all

concurrency:
group: transfer
cancel-in-progress: true
cancel-in-progress: false

jobs:
fetch_issues:
Expand Down
66 changes: 35 additions & 31 deletions scripts/transfer-issues.sh
Expand Up @@ -16,6 +16,7 @@ set -xue

# The label ID for https://github.com/mozilla/addons/labels/migration%3A2024
MIGRATION_LABEL_ID="LA_kwDOAn4H8M8AAAABmbq8hA"
MIGRATION_NO_JIRA_ID="LA_kwDOAPqAY88AAAABm5JiFA"

REPOSITORY_OWNER="mozilla"
TO_NAME="addons"
Expand Down Expand Up @@ -49,60 +50,60 @@ if [[ ! "$ALLOWED_REPOS" =~ (^|,)"$FROM_NAME"(,|$) ]]; then
exit 1
fi

function get_single_issue() {
local issues_query="""
rate_limit=$(gh api /rate_limit)
echo "rate_limit: $rate_limit"
graphql_remaining=$(echo $rate_limit | jq -r '.resources.graphql.remaining')
core_remaining=$(echo $rate_limit | jq -r '.resources.core.remaining')
rate_limit_remaining=$(echo $rate_limit | jq -r '.rate.remaining')

if [[ "$graphql_remaining" -eq 0 || "$core_remaining" -eq 0 || "$rate_limit_remaining" -eq 0 ]]; then
echo "Rate limit exceeded. Exiting..."
exit 1
fi

if [[ -n "$ISSUE_NUMBER" ]]; then
echo "Transferring issue $ISSUE_NUMBER from \"$FROM_REPO\" to \"$TO_REPO\""
issues_query="""
query {
repository(owner: \"$REPOSITORY_OWNER\", name: \"$FROM_NAME\") {
issue(number: $ISSUE_NUMBER) {
id
body
url
}
}
}
"""

local issues=$(gh api graphql -f query="$issues_query" --jq '.data.repository.issue')

if [[ "$issues" == *"errors"* ]]; then
echo "Error: $issues"
exit 1
fi

echo "$issues"
}
issues=$(gh api graphql -f query="$issues_query" --jq '.data.repository.issue')
else
echo "Transferring $COUNT issues from \"$FROM_REPO\" to \"$TO_REPO\""

function get_multiple_issues() {
local issues_query="""
issues_query="""
query {
repository(owner: \"$REPOSITORY_OWNER\", name: \"$FROM_NAME\") {
issues(first: $COUNT, states: $STATES, orderBy: {field: CREATED_AT, direction: ASC}) {
nodes {
id
body
url
}
}
}
}
"""

local issues=$(gh api graphql -f query="$issues_query" --jq '.data.repository.issues.nodes[]')

if [[ "$issues" == *"errors"* ]]; then
echo "Error: $issues"
exit 1
fi

echo "$issues"
}
issues=$(gh api graphql -f query="$issues_query" --jq '.data.repository.issues.nodes[]')
fi

if [[ -n "$ISSUE_NUMBER" ]]; then
echo "Transferring issue $ISSUE_NUMBER from \"$FROM_REPO\" to \"$TO_REPO\""
issues=$(get_single_issue)
else
echo "Transferring $COUNT issues from \"$FROM_REPO\" to \"$TO_REPO\""
issues=$(get_multiple_issues)
if [[ -z "$issues" ]]; then
echo "No issues found. Exiting..."
exit 1
fi

# echo each issue .url property
echo "$issues" | jq -r '.url'

transfer_mutation="mutation {"
comment_mutation="mutation {"

Expand All @@ -127,8 +128,10 @@ while IFS= read -r issue; do
if [ -n "$jira_link" ]; then
comment_body="Old Jira Ticket: $jira_link"
comment_mutation+=" t${comment_counter}: addComment(input: { subjectId: \"${issue_id}\", body: \"${comment_body}\" }) { __typename }"
comment_counter=$((comment_counter+1))
else
comment_mutation+=" t${comment_counter}: addLabelsToLabelable(input: {labelableId: \"$issue_id\", labelIds: [\"$MIGRATION_NO_JIRA_ID\"]}) { __typename }"
fi
comment_counter=$((comment_counter+1))

done <<< "$issues"

Expand All @@ -151,10 +154,11 @@ label_mutation="mutation {"

label_counter=1

while IFS= read -r id; do
while IFS= read -r issue; do
id=$(echo "$issue" | jq -r '.id')
label_mutation+=" l${label_counter}: addLabelsToLabelable(input: {labelableId: \"$id\", labelIds: [\"$label_id\", \"$MIGRATION_LABEL_ID\"]}) { __typename }"
label_counter=$((label_counter+1))
done <<< $(echo "$new_issues" | jq -r '.id')
done <<< "$new_issues"

label_mutation+=" }"

Expand Down

0 comments on commit 89ae676

Please sign in to comment.