Skip to content
This repository was archived by the owner on Apr 17, 2019. It is now read-only.
Closed
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
14 changes: 12 additions & 2 deletions github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,19 @@ func GetLabelsWithPrefix(labels []github.Label, prefix string) []string {
return ret
}

func GetLabelSet(labels []github.Label) util.StringSet {
set := util.NewStringSet()
for _, label := range labels {
if label.Name != nil {
set.Insert(*label.Name)
}
}
return set
}

func (config *GithubConfig) AddLabels(prNum int, labels []string) error {
if config.DryRun {
glog.Infof("Would have added labels %v to PR %d --dry-run is set", labels, prNum)
glog.Infof("Would have added labels %v to PR %d but --dry-run is set", labels, prNum)
return nil
}
if _, _, err := config.client.Issues.AddLabelsToIssue(config.Org, config.Project, prNum, labels); err != nil {
Expand All @@ -175,7 +185,7 @@ func (config *GithubConfig) AddLabels(prNum int, labels []string) error {

func (config *GithubConfig) RemoveLabel(prNum int, label string) error {
if config.DryRun {
glog.Infof("Would have removed label %q to PR %d --dry-run is set", label, prNum)
glog.Infof("Would have removed label %q to PR %d but --dry-run is set", label, prNum)
return nil
}
if _, err := config.client.Issues.RemoveLabelForIssue(config.Org, config.Project, prNum, label); err != nil {
Expand Down
73 changes: 73 additions & 0 deletions mungegithub/pulls/label_based_on_path.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
Copyright 2015 The Kubernetes Authors All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package pulls

import (
"fmt"
"strings"

github_util "k8s.io/contrib/github"
"k8s.io/contrib/mungegithub/config"
"k8s.io/kubernetes/pkg/util"

"github.com/golang/glog"
"github.com/google/go-github/github"
"github.com/spf13/cobra"
)

var (
_ = fmt.Print
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes it so I can add/remove fmt.Print lines to debug without the compiler whining the "fmt" is unused.

labelMap = map[string]string{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this an external config file so that I don't have to re-compile the binary to rev it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

follow on PR does just that.

"docs/proposals": "kind/design",
"pkg/api/register.go": "kind/new-api",
"pkg/expapi/register.go": "kind/new-api",
"pkg/api/types.go": "kind/api-change",
"pkg/expapi/types.go": "kind/api-change",
}
)

type PathLabelMunger struct{}

func init() {
RegisterMungerOrDie(PathLabelMunger{})
}

func (PathLabelMunger) Name() string { return "path-label" }

func (PathLabelMunger) AddFlags(cmd *cobra.Command) {}

func (PathLabelMunger) MungePullRequest(config *config.MungeConfig, pr *github.PullRequest, issue *github.Issue, commits []github.RepositoryCommit, events []github.IssueEvent) {
glog.V(8).Infof("Checking out PR %d\n", *pr.Number)

currentLabels := github_util.GetLabelSet(issue.Labels)

mungerLabels := util.StringSet{}
for _, c := range commits {
for _, f := range c.Files {
for prefix, label := range labelMap {
if strings.HasPrefix(*f.Filename, prefix) {
mungerLabels.Insert(label)
}
}
}
}

needsLabels := mungerLabels.Difference(currentLabels)
if len(needsLabels) != 0 {
config.AddLabels(*pr.Number, needsLabels.List())
}
}
2 changes: 1 addition & 1 deletion mungegithub/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

while true; do
/mungegithub \
--pr-mungers=blunderbuss,needs-rebase,ok-to-test,ping-ci,size \
--pr-mungers=blunderbuss,needs-rebase,ok-to-test,ping-ci,size,path-label \
--blunderbuss-config=/blunderbuss.yml \
--token-file=/etc/secret-volume/token
sleep 600
Expand Down