Skip to content

Commit

Permalink
add cusomised max number of changes and label comment options
Browse files Browse the repository at this point in the history
  • Loading branch information
PraiseXI committed Feb 7, 2024
1 parent 8d1d773 commit 32007b1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
14 changes: 5 additions & 9 deletions AntiSpamPRLabeler.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
$repoOwner = `${{ github.repository_owner }}`
$repoName = `${{ github.event.repository.name }}`
$GITHUB_TOKEN = $env:GITHUB_TOKEN
$maxChangesForLabel = $env:MAX_CHANGES_FOR_LABEL
$labelMessage = $env:LABEL_MESSAGE

# Base64 encode the GitHub Token
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$GITHUB_TOKEN"))
Expand Down Expand Up @@ -50,14 +52,8 @@ foreach ($pr in $response) {
$deletions = $pr.deletions
$totalChanges = $additions + $deletions

$label = switch ($totalChanges) {
{ $_ -le 10 } { "Potential Spam" }
Default { "" }
}

if ($label -ne "") {
Add-LabelToPullRequest -prNumber $prNumber -label $label
$comment = "This PR has been automatically labeled as 'Potential Spam' due to its size. Please review."
Add-CommentToPullRequest -prNumber $prNumber -comment $comment
if ($totalChanges -le $maxChangesForLabel) {
Add-LabelToPullRequest -prNumber $prNumber -label "Potential Spam"
Add-CommentToPullRequest -prNumber $prNumber -comment $labelMessage
}
}
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@ To incorporate this action into your workflow, add the following step to your Gi
uses: PraiseXI/AntiSpamPRLabeler@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

max-changes-for-label: '10' #default is 2
label-message: 'This PR has been automatically labeled as "Potential Spam" due to its size. Please review.'
# Optional, default message provided
```
This snippet shows how to configure the action to use the built-in `GITHUB_TOKEN` for API requests.
This snippet shows how to configure the action to use the built-in `GITHUB_TOKEN` for API requests and allows for optional parameters to customize the labeling and commenting behavior.
## Inputs

`repo-token`: **Required**. The GitHub token used to authenticate API requests. This should generally be set to **`${{ secrets.GITHUB_TOKEN }}`** to utilize the automatic token GitHub provides.

`max-changes-for-label`: **Optional**. The maximum number of changes a PR can have before being labeled as 'Potential Spam'. Default is 2.

`label-message`: **Optional**. The message to comment on PRs that are labeled as 'Potential Spam'. A default message is provided if not set.

## Outputs
There are no outputs defined for this action. Its primary function is to label and comment on PRs directly.

Expand All @@ -45,6 +51,9 @@ jobs:
uses: PraiseXI/AntiSpamPRLabeler@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
max-changes-for-label: '2' # Optional, default is 2
label-message: 'Custom message for labeled PRs.'
# Optional, your custom message here
```
## Contributing
Contributions to the PR Labeler and Commenter Action are welcome! Please submit pull requests or open issues with your suggestions.
Expand Down
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ inputs:
repo-token:
description: 'The GitHub token for authentication.'
required: true
max-changes-for-label:
description: 'The maximum number of changes a PR can have before being labeled.'
required: true
default: '2'
label-message:
description: 'Custom message to post on PRs that are labeled as potential spam.'
required: false
default: 'This PR has been automatically labeled as "Potential Spam" due to its size. Please review.'
runs:
using: 'composite'
steps:
Expand Down

0 comments on commit 32007b1

Please sign in to comment.