-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
51 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,60 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"strings" | ||
) | ||
|
||
var ( | ||
skipLabelName = "skip-changelog-check" | ||
skipTitles = []string{"chore", "test", "doc", "ci"} // Dependabot uses chore. | ||
) | ||
|
||
func main() { | ||
fmt.Println("PR_TITLE", os.Getenv("PR_TITLE")) | ||
fmt.Println("PR_NUMBER", os.Getenv("PR_NUMBER")) | ||
fmt.Println("PR_LABELS", os.Getenv("PR_LABELS")) | ||
var ( | ||
title = os.Getenv("PR_TITLE") | ||
number = os.Getenv("PR_NUMBER") | ||
jsonLabels = os.Getenv("PR_LABELS") | ||
) | ||
if title == "" || number == "" || jsonLabels == "" { | ||
panic("Environment variables PR_TITLE, PR_NUMBER and PR_LABELS are required") | ||
} | ||
var labels []string | ||
if err := json.Unmarshal([]byte(jsonLabels), &labels); err != nil { | ||
panic(fmt.Sprintf("PR_LABELS is not a stringified JSON array: %v", err)) | ||
} | ||
|
||
if skipTitle(title) { | ||
fmt.Println("Skipping changelog check because PR title") | ||
return | ||
} | ||
|
||
if skipLabel(labels) { | ||
fmt.Printf("Skipping changelog check because PR label found: %s\n", skipLabelName) | ||
return | ||
} | ||
|
||
fmt.Println("PR_TITLE", title) | ||
fmt.Println("PR_NUMBER", number) | ||
fmt.Println("PR_LABELS", labels) | ||
} | ||
|
||
func skipTitle(title string) bool { | ||
for _, item := range skipTitles { | ||
if strings.HasPrefix(title, item+":") { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
func skipLabel(labels []string) bool { | ||
for _, label := range labels { | ||
if label == skipLabelName { | ||
return true | ||
} | ||
} | ||
return false | ||
} |