diff options
Diffstat (limited to '.github/workflows')
-rw-r--r-- | .github/workflows/labeler.yml | 77 | ||||
-rw-r--r-- | .github/workflows/webhook_translate.yml | 14 |
2 files changed, 10 insertions, 81 deletions
diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml deleted file mode 100644 index f1ec8445..00000000 --- a/.github/workflows/labeler.yml +++ /dev/null @@ -1,77 +0,0 @@ -name: Automatic Labeling - -on: - pull_request_target: - types: [opened, synchronize, reopened, ready_for_review, converted_to_draft, closed] - pull_request_review: - types: [submitted, dismissed] - -jobs: - labeler: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set Labels - uses: actions/github-script@v7 - with: - github-token: ${{ secrets.GH_LABELER }} - script: | - const { owner, repo, number: pull_number } = context.issue; - const { data: pullRequest } = await github.rest.pulls.get({ owner, repo, pull_number }); - const labels = pullRequest.labels.map(label => label.name); - - let label = ''; - - if (pullRequest.draft) { - label = 'wip'; - } else if (pullRequest.mergeable_state === 'dirty') { - label = 'merge conflicts'; - } else if (pullRequest.merged) { - label = '' - } else { - const { data: reviews } = await github.rest.pulls.listReviews({ owner, repo, pull_number }); - const { data: commits } = await github.rest.pulls.listCommits({ owner, repo, pull_number }); - - const filteredReviews = reviews.filter(review => review.state === 'CHANGES_REQUESTED' || review.state === 'APPROVED'); - const lastReview = filteredReviews.sort((a, b) => new Date(b.submitted_at) - new Date(a.submitted_at))[0]; - const lastCommit = commits.sort((a, b) => new Date(b.commit.committer.date) - new Date(a.commit.committer.date))[0]; - - if (!lastReview || new Date(lastReview.submitted_at) < new Date(lastCommit.commit.committer.date)) { - label = 'reviews needed'; - } else if (lastReview.state === 'CHANGES_REQUESTED') { - label = 'changes requested'; - } else if (lastReview.state === 'APPROVED') { - label = 'merge me please'; - } - } - - // if label is not set change the label - if (!labels.includes(label)) { - // list of labels to be removed - const labelsToRemove = ['merge me please', 'reviews needed', 'merge conflicts', 'wip', 'changes requested']; - - // remove all label from list - const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue({ owner, repo, issue_number: pull_number }); - for (const { name } of currentLabels) { - if (labelsToRemove.includes(name)) { - await github.rest.issues.removeLabel({ - owner, - repo, - issue_number: pull_number, - name - }); - } - } - - // add label - if (label) { - await github.rest.issues.addLabels({ - owner, - repo, - issue_number: pull_number, - labels: [label] - }); - } - }
\ No newline at end of file diff --git a/.github/workflows/webhook_translate.yml b/.github/workflows/webhook_translate.yml index 5d1208fa..1998ee73 100644 --- a/.github/workflows/webhook_translate.yml +++ b/.github/workflows/webhook_translate.yml @@ -15,10 +15,10 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 with: - fetch-depth: 2 + fetch-depth: 0 - name: Set up Go - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: go-version: '1.20' @@ -39,13 +39,14 @@ jobs: OUTPUT="\`\`\`diff $OUTPUT \`\`\`" + OUTPUT=$(jq -Rn --arg str "$OUTPUT" '$str' | sed -E "s|^(['\"])(.*)\1$|\2|g") JSON_PAYLOAD='{ "content": "<@&1134566053138145330>", "embeds": [ { "title": "Something Changed (Click me)", - "description": "'"${OUTPUT//$'\n'/\\n}"'", + "description": "'"${OUTPUT}"'", "url": "https://translate.hysky.de/projects/Skyblocker/skyblocker", "color": 5808639, "image": { @@ -56,4 +57,9 @@ jobs: "attachments": [] }' - curl -H "Content-Type: application/json" --data-binary "$JSON_PAYLOAD" "${{ secrets.DISCORD_TRANSLATE_WEBHOOK }}" + if echo "$JSON_PAYLOAD" | jq . &>/dev/null; then + curl -H "Content-Type: application/json" --data-binary "$JSON_PAYLOAD" "${{ secrets.DISCORD_TRANSLATE_WEBHOOK }}" + else + echo "Error:" + echo "$JSON_PAYLOAD" + fi
\ No newline at end of file |