Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

label-pull-request: add except #89

Merged
merged 4 commits into from
Sep 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions label-pull-requests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ Will remove labels from a pull request that no longer apply.
"content": "bottle :unneeded",
"path": "Formula/.+"
},
{
"label": "legacy",
"path": "Formula/.+@.+",
"except": [
"Formula/python@3.8",
"Formula/python@3.9"
]
},
{
"label": "missing license",
"missing_content": "license \"[^"]+\"",
Expand Down
8 changes: 8 additions & 0 deletions label-pull-requests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ inputs:
- "label" (required): Label name, that should be added to PR
- "status" (optional): File status, one of: added, modified, removed
- "path" (optional): Changed file path, regex matching
- "except" (optional): File path(s) to exclude
- "content" (optional): Changed file content, regex matching
- "missing_content" (optional): Missing file content, regex matching

Expand All @@ -29,6 +30,13 @@ inputs:
}, {
"label": "bottle unneeded",
"content": "bottle :unneeded"
}, {
"label": "legacy",
"path": "Formula/.+@.+",
"except": [
"Formula/python@3.8",
"Formula/python@3.9"
]
}, {
"label": "missing license",
"missing_content": "license \"[^"]+\""
Expand Down
39 changes: 31 additions & 8 deletions label-pull-requests/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,7 @@ async function main() {
}

// Check constraints
if (
(!constraint.status || file.status == constraint.status) &&
(!constraint.path || file.filename.match(constraint.path)) &&
(!constraint.content || file.content.match(constraint.content)) &&
(!constraint.missing_content || !file.content.match(constraint.missing_content))
) {
constraintApplies = true
}
constraintApplies = doesConstraintApply(constraint, file)

if (labelExists && constraintApplies) {
continue
Expand Down Expand Up @@ -153,4 +146,34 @@ async function main() {
}
}

function doesConstraintApply(constraint, file) {
if (constraint.status && file.status != constraint.status) {
return false
}

if (constraint.path && !file.filename.match(constraint.path)) {
return false
}

if (constraint.except) {
if (Array.isArray(constraint.except)) {
if (constraint.except.includes(file.filename)) {
return false
}
} else if (file.filename == constraint.except) {
return false
}
}

if (constraint.content && !file.content.match(constraint.content)) {
return false
}

if (constraint.missing_content && file.content.match(constraint.missing_content)) {
return false
}

return true
}

main()