2019-05-07 06:42:51 +05:30
|
|
|
// Copyright 2017 The go-github AUTHORS. All rights reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package github
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ListProjects lists the projects for an organization.
|
|
|
|
//
|
2021-08-10 15:19:43 +05:30
|
|
|
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/projects/#list-organization-projects
|
2020-07-31 19:52:34 +05:30
|
|
|
func (s *OrganizationsService) ListProjects(ctx context.Context, org string, opts *ProjectListOptions) ([]*Project, *Response, error) {
|
2019-05-07 06:42:51 +05:30
|
|
|
u := fmt.Sprintf("orgs/%v/projects", org)
|
2020-07-31 19:52:34 +05:30
|
|
|
u, err := addOptions(u, opts)
|
2019-05-07 06:42:51 +05:30
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
req, err := s.client.NewRequest("GET", u, nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: remove custom Accept header when this API fully launches.
|
|
|
|
req.Header.Set("Accept", mediaTypeProjectsPreview)
|
|
|
|
|
|
|
|
var projects []*Project
|
|
|
|
resp, err := s.client.Do(ctx, req, &projects)
|
|
|
|
if err != nil {
|
|
|
|
return nil, resp, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return projects, resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateProject creates a GitHub Project for the specified organization.
|
|
|
|
//
|
2021-08-10 15:19:43 +05:30
|
|
|
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/projects/#create-an-organization-project
|
2020-07-31 19:52:34 +05:30
|
|
|
func (s *OrganizationsService) CreateProject(ctx context.Context, org string, opts *ProjectOptions) (*Project, *Response, error) {
|
2019-05-07 06:42:51 +05:30
|
|
|
u := fmt.Sprintf("orgs/%v/projects", org)
|
2020-07-31 19:52:34 +05:30
|
|
|
req, err := s.client.NewRequest("POST", u, opts)
|
2019-05-07 06:42:51 +05:30
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: remove custom Accept header when this API fully launches.
|
|
|
|
req.Header.Set("Accept", mediaTypeProjectsPreview)
|
|
|
|
|
|
|
|
project := &Project{}
|
|
|
|
resp, err := s.client.Do(ctx, req, project)
|
|
|
|
if err != nil {
|
|
|
|
return nil, resp, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return project, resp, nil
|
|
|
|
}
|