本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.0KB

  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. // ProjectListOptions specifies the optional parameters to the
  11. // OrganizationsService.ListProjects and RepositoriesService.ListProjects methods.
  12. type ProjectListOptions struct {
  13. // Indicates the state of the projects to return. Can be either open, closed, or all. Default: open
  14. State string `url:"state,omitempty"`
  15. ListOptions
  16. }
  17. // ListProjects lists the projects for a repo.
  18. //
  19. // GitHub API docs: https://developer.github.com/v3/projects/#list-repository-projects
  20. func (s *RepositoriesService) ListProjects(ctx context.Context, owner, repo string, opt *ProjectListOptions) ([]*Project, *Response, error) {
  21. u := fmt.Sprintf("repos/%v/%v/projects", owner, repo)
  22. u, err := addOptions(u, opt)
  23. if err != nil {
  24. return nil, nil, err
  25. }
  26. req, err := s.client.NewRequest("GET", u, nil)
  27. if err != nil {
  28. return nil, nil, err
  29. }
  30. // TODO: remove custom Accept headers when APIs fully launch.
  31. req.Header.Set("Accept", mediaTypeProjectsPreview)
  32. var projects []*Project
  33. resp, err := s.client.Do(ctx, req, &projects)
  34. if err != nil {
  35. return nil, resp, err
  36. }
  37. return projects, resp, nil
  38. }
  39. // CreateProject creates a GitHub Project for the specified repository.
  40. //
  41. // GitHub API docs: https://developer.github.com/v3/projects/#create-a-repository-project
  42. func (s *RepositoriesService) CreateProject(ctx context.Context, owner, repo string, opt *ProjectOptions) (*Project, *Response, error) {
  43. u := fmt.Sprintf("repos/%v/%v/projects", owner, repo)
  44. req, err := s.client.NewRequest("POST", u, opt)
  45. if err != nil {
  46. return nil, nil, err
  47. }
  48. // TODO: remove custom Accept headers when APIs fully launch.
  49. req.Header.Set("Accept", mediaTypeProjectsPreview)
  50. project := &Project{}
  51. resp, err := s.client.Do(ctx, req, project)
  52. if err != nil {
  53. return nil, resp, err
  54. }
  55. return project, resp, nil
  56. }
上海开阖软件有限公司 沪ICP备12045867号-1