Skip to content

Commit

Permalink
feat: prints unlabeled PRs to stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
bartoszmajsak committed Apr 14, 2020
1 parent e58ddc8 commit 2bf6431
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func NewCmd() *cobra.Command {
releaseInfo := make(chan string, 1)

rootCmd := &cobra.Command{
Use: "cmd",
Use: "ghc",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error { //nolint[:unparam]
if v.Released() {
go func() {
Expand Down Expand Up @@ -63,7 +63,7 @@ func NewCmd() *cobra.Command {
rootCmd.PersistentFlags().
StringVarP(&configFile, "config", "c", ".ghc.config.yaml",
fmt.Sprintf("config file (supported formats: %s)", strings.Join(config.SupportedExtensions(), ", ")))
rootCmd.Flags().Bool("version", false, "prints the version number of ike cli")
rootCmd.Flags().Bool("version", false, "prints the version number")
rootCmd.PersistentFlags().String("help-format", "standard", "prints help in asciidoc table")
if err := rootCmd.PersistentFlags().MarkHidden("help-format"); err != nil {
fmt.Printf("failed while trying to hide a flag: %s\n", err)
Expand Down
16 changes: 13 additions & 3 deletions pkg/github/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,15 @@ func FindAssociatedPRs(client *githubv4.Client, repo []string, matchingCommit Ma
})
check.IfError(err)

var prs []PullRequest
var (
prs []PullRequest
unlabeledPRs bool
)
for _, node := range associatedPRs.Repository.DefaultBranch.Target.Commit.History.Nodes {
if node.Oid != matchingCommit.Repository.Object.Commit.Oid && node.MessageHeadline != "release: next iteration" {
for _, pr := range node.AssociatedPullRequests.Nodes {
if len(pr.Labels.Nodes) == 0 {
fmt.Printf("\x1b[33;1m%s\x1b[0m\n", fmt.Sprintf("This PR has no labels: %s", pr.Permalink))
unlabeledPRs = true
}
prs = append(prs, PullRequest{
RelatedCommit: Commit{
Expand All @@ -119,5 +122,12 @@ func FindAssociatedPRs(client *githubv4.Client, repo []string, matchingCommit Ma
}
}
}
return removeDuplicates(prs)
withoutDuplicates := removeDuplicates(prs)
if unlabeledPRs {
fmt.Fprint(os.Stderr, "#### Found unlabeled PRs\n\n")
for i := range withoutDuplicates {
fmt.Fprintf(os.Stderr, "* %s\n", withoutDuplicates[i].Permalink)
}
}
return withoutDuplicates
}

0 comments on commit 2bf6431

Please sign in to comment.