Skip to content

Instantly share code, notes, and snippets.

@jniltinho
Last active September 22, 2022 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jniltinho/0f941373da4b59b51c0150b4f7c35613 to your computer and use it in GitHub Desktop.
Save jniltinho/0f941373da4b59b51c0150b4f7c35613 to your computer and use it in GitHub Desktop.
Regex Jira ID Golang
package main
// go mod init get-jira-id
// gofmt -w main.go
// go build -ldflags="-s -w"
// upx --best --lzma get-jira-id
// ./get-jira-id --issue=feature/Pbo-784-epic
import (
"flag"
"os"
"regexp"
"strings"
)
func main() {
issueID := flag.String("issue", "feature/PBO-5599-epic", "Issue ID name")
flag.Parse()
GetIssueID(*issueID)
//GetIssueID("fc/PBO-559999-epic-NNNN-VVVGGG")
}
func GetIssueID(issueIDName string) {
re := regexp.MustCompile(`(\b(pbo|asd|asdp|ae|at))+-[\d]+`)
matches := re.FindAllString(strings.ToLower(issueIDName), -1)
if len(matches) == 0 {
print("not_found_jira_id")
os.Exit(1)
}
print(matches[0])
os.Exit(0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment