orgs_projects.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2017 The go-github AUTHORS. All rights reserved.
  2. //
  3. // Use of this source code is governed by a BSD-style
  4. // license that can be found in the LICENSE file.
  5. package github
  6. import (
  7. "context"
  8. "fmt"
  9. )
  10. // ListProjects lists the projects for an organization.
  11. //
  12. // GitHub API docs: https://developer.github.com/v3/projects/#list-organization-projects
  13. func (s *OrganizationsService) ListProjects(ctx context.Context, org string, opt *ProjectListOptions) ([]*Project, *Response, error) {
  14. u := fmt.Sprintf("orgs/%v/projects", org)
  15. u, err := addOptions(u, opt)
  16. if err != nil {
  17. return nil, nil, err
  18. }
  19. req, err := s.client.NewRequest("GET", u, nil)
  20. if err != nil {
  21. return nil, nil, err
  22. }
  23. // TODO: remove custom Accept header when this API fully launches.
  24. req.Header.Set("Accept", mediaTypeProjectsPreview)
  25. var projects []*Project
  26. resp, err := s.client.Do(ctx, req, &projects)
  27. if err != nil {
  28. return nil, resp, err
  29. }
  30. return projects, resp, nil
  31. }
  32. // CreateProject creates a GitHub Project for the specified organization.
  33. //
  34. // GitHub API docs: https://developer.github.com/v3/projects/#create-an-organization-project
  35. func (s *OrganizationsService) CreateProject(ctx context.Context, org string, opt *ProjectOptions) (*Project, *Response, error) {
  36. u := fmt.Sprintf("orgs/%v/projects", org)
  37. req, err := s.client.NewRequest("POST", u, opt)
  38. if err != nil {
  39. return nil, nil, err
  40. }
  41. // TODO: remove custom Accept header when this API fully launches.
  42. req.Header.Set("Accept", mediaTypeProjectsPreview)
  43. project := &Project{}
  44. resp, err := s.client.Do(ctx, req, project)
  45. if err != nil {
  46. return nil, resp, err
  47. }
  48. return project, resp, nil
  49. }