Skip to content

Commit

Permalink
Plugin to add issue and PR to GitHub Project
Browse files Browse the repository at this point in the history
  • Loading branch information
taragu committed Feb 10, 2019
1 parent d11b3ef commit adcac06
Show file tree
Hide file tree
Showing 6 changed files with 341 additions and 29 deletions.
18 changes: 9 additions & 9 deletions prow/github/client.go
Expand Up @@ -2553,7 +2553,7 @@ func (c *Client) CreateProjectCard(columnID int, projectCard ProjectCard) (*Proj
// GetProjectCard of a specific issue or PR for a specific board/project
//
// See https://developer.github.com/v3/projects/cards/#list-project-cards
func (c *Client) GetProjectCard(projectID int, number int) (ProjectCard, error) {
func (c *Client) GetProjectCard(projectID int, number int) (*ProjectCard, error) {
c.log("GetProjectCard", projectID, number)
// Get project cards for each project and look for the content url
if c.fake {
Expand All @@ -2566,9 +2566,9 @@ func (c *Client) GetProjectCard(projectID int, number int) (ProjectCard, error)
}
// Check all columns for the project card
for _, co := range columns {
path := fmt.Sprintf("/projects/columns/:%s/cards", co.ID)
path := fmt.Sprintf("/projects/columns/:%d/cards", co.ID)
var cards []ProjectCard
err := c.ReadPaginatedResults{
err := c.readPaginatedResults(
path,
acceptNone,
func() interface{} {
Expand All @@ -2577,13 +2577,13 @@ func (c *Client) GetProjectCard(projectID int, number int) (ProjectCard, error)
func(obj interface{}) {
cards = append(cards, *(obj.(*[]ProjectCard))...)
},
}
)
if err != nil {
return nil, err
}
for _, card := range cards {
if card.contentID == number {
return card, nil
if card.ContentID == number {
return &card, nil
}
}
}
Expand All @@ -2597,9 +2597,9 @@ func (c *Client) MoveProjectCard(projectCardID int, newColumnID int) error {
c.log("MoveProjectCard", projectCardID, newColumnID)
_, err := c.request(&request{
method: http.MethodPost,
path: fmt.Sprintf("/projects/columns/cards/:%s/moves", projectCardID),
path: fmt.Sprintf("/projects/columns/cards/:%d/moves", projectCardID),
accept: "application/vnd.github.symmetra-preview+json", // allow the description field -- https://developer.github.com/changes/2018-02-22-label-description-search-preview/
requestBody: Label{column_id: newColumnID},
requestBody: fmt.Sprintf("{column_id: %d}", newColumnID),
exitCodes: []int{201},
}, nil)
return err
Expand All @@ -2613,7 +2613,7 @@ func (c *Client) DeleteProjectCard(projectCardID int) error {
_, err := c.request(&request{
method: http.MethodDelete,
accept: "application/vnd.github.symmetra-preview+json", // allow the description field -- https://developer.github.com/changes/2018-02-22-label-description-search-preview/
path: fmt.Sprintf("/projects/columns/cards/:%s", projectCardID),
path: fmt.Sprintf("/projects/columns/cards/:%d", projectCardID),
exitCodes: []int{204},
}, nil)
return err
Expand Down
13 changes: 13 additions & 0 deletions prow/plugins.yaml
Expand Up @@ -222,6 +222,19 @@ repo_milestone:
maintainers_id: 2460384
maintainers_team: kubernetes-milestone-maintainers

repo_project:
# Default maintainer for projects
'':
# You can curl the following endpoint in order to determine the github ID of your team
# responsible for maintaining the projects:
# curl -H "Authorization: token <token>" https://api.github.com/orgs/<org-name>/teams
project_maintainers_id: 2460384
project_maintainers_team: kubernetes-project-maintainers
default_column_names:
- To do
- To triage
- Backlog

config_updater:
maps:
label_sync/labels.yaml:
Expand Down
1 change: 1 addition & 0 deletions prow/plugins/BUILD.bazel
Expand Up @@ -79,6 +79,7 @@ filegroup(
"//prow/plugins/override:all-srcs",
"//prow/plugins/owners-label:all-srcs",
"//prow/plugins/pony:all-srcs",
"//prow/plugins/project:all-srcs",
"//prow/plugins/releasenote:all-srcs",
"//prow/plugins/require-matching-label:all-srcs",
"//prow/plugins/requiresig:all-srcs",
Expand Down
55 changes: 35 additions & 20 deletions prow/plugins/config.go
Expand Up @@ -51,26 +51,27 @@ type Configuration struct {
Owners Owners `json:"owners,omitempty"`

// Built-in plugins specific configuration.
Approve []Approve `json:"approve,omitempty"`
UseDeprecatedSelfApprove bool `json:"use_deprecated_2018_implicit_self_approve_default_migrate_before_july_2019,omitempty"`
UseDeprecatedReviewApprove bool `json:"use_deprecated_2018_review_acts_as_approve_default_migrate_before_july_2019,omitempty"`
Blockades []Blockade `json:"blockades,omitempty"`
Blunderbuss Blunderbuss `json:"blunderbuss,omitempty"`
Cat Cat `json:"cat,omitempty"`
CherryPickUnapproved CherryPickUnapproved `json:"cherry_pick_unapproved,omitempty"`
ConfigUpdater ConfigUpdater `json:"config_updater,omitempty"`
Golint *Golint `json:"golint,omitempty"`
Heart Heart `json:"heart,omitempty"`
Label *Label `json:"label,omitempty"`
Lgtm []Lgtm `json:"lgtm,omitempty"`
RepoMilestone map[string]Milestone `json:"repo_milestone,omitempty"`
RequireMatchingLabel []RequireMatchingLabel `json:"require_matching_label,omitempty"`
RequireSIG RequireSIG `json:"requiresig,omitempty"`
Slack Slack `json:"slack,omitempty"`
SigMention SigMention `json:"sigmention,omitempty"`
Size *Size `json:"size,omitempty"`
Triggers []Trigger `json:"triggers,omitempty"`
Welcome []Welcome `json:"welcome,omitempty"`
Approve []Approve `json:"approve,omitempty"`
UseDeprecatedSelfApprove bool `json:"use_deprecated_2018_implicit_self_approve_default_migrate_before_july_2019,omitempty"`
UseDeprecatedReviewApprove bool `json:"use_deprecated_2018_review_acts_as_approve_default_migrate_before_july_2019,omitempty"`
Blockades []Blockade `json:"blockades,omitempty"`
Blunderbuss Blunderbuss `json:"blunderbuss,omitempty"`
Cat Cat `json:"cat,omitempty"`
CherryPickUnapproved CherryPickUnapproved `json:"cherry_pick_unapproved,omitempty"`
ConfigUpdater ConfigUpdater `json:"config_updater,omitempty"`
Golint *Golint `json:"golint,omitempty"`
Heart Heart `json:"heart,omitempty"`
Label *Label `json:"label,omitempty"`
Lgtm []Lgtm `json:"lgtm,omitempty"`
RepoMilestone map[string]Milestone `json:"repo_milestone,omitempty"`
ProjectConfigMap map[string]ProjectConfig `json:"repo_project,omitempty"`
RequireMatchingLabel []RequireMatchingLabel `json:"require_matching_label,omitempty"`
RequireSIG RequireSIG `json:"requiresig,omitempty"`
Slack Slack `json:"slack,omitempty"`
SigMention SigMention `json:"sigmention,omitempty"`
Size *Size `json:"size,omitempty"`
Triggers []Trigger `json:"triggers,omitempty"`
Welcome []Welcome `json:"welcome,omitempty"`
}

// Golint holds configuration for the golint plugin
Expand Down Expand Up @@ -372,6 +373,20 @@ type Milestone struct {
MaintainersTeam string `json:"maintainers_team,omitempty"`
}

// ProjectConfig contains the configuration options for the project plugin
type ProjectConfig struct {
// ID of the github team for the project maintainers
// You can curl the following endpoint in order to determine the github ID of your team
// responsible for maintaining the projects:
// curl -H "Authorization: token <token>" https://api.github.com/orgs/<org-name>/teams
ProjectMaintainersID int `json:"project_maintainers_id,omitempty"`
ProjectMaintainersTeam string `json:"project_maintainers_team,omitempty"`

// If no column is provided when adding an issue/PR to a project, the issue/PR
// will be added to one of these columns (in the order they are specified)
DefaultColumnNames []string `json:"default_column_names,omitempty"`
}

// Slack contains the configuration for the slack plugin.
type Slack struct {
MentionChannels []string `json:"mentionchannels,omitempty"`
Expand Down
28 changes: 28 additions & 0 deletions prow/plugins/project/BUILD.bazel
@@ -0,0 +1,28 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = ["project.go"],
importpath = "k8s.io/test-infra/prow/plugins/project",
visibility = ["//visibility:public"],
deps = [
"//prow/github:go_default_library",
"//prow/pluginhelp:go_default_library",
"//prow/plugins:go_default_library",
"//vendor/github.com/sirupsen/logrus:go_default_library",
],
)

filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)

filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

0 comments on commit adcac06

Please sign in to comment.