Skip to content

Commit

Permalink
skip logic
Browse files Browse the repository at this point in the history
  • Loading branch information
lantoli committed Apr 9, 2024
1 parent 9fb7255 commit 82f4d28
Showing 1 changed file with 51 additions and 3 deletions.
54 changes: 51 additions & 3 deletions tools/changelog-pr-check/changelog-pr-check.go
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
}

0 comments on commit 82f4d28

Please sign in to comment.