...

Source file src/github.com/google/go-github/v45/github/orgs_projects.go

Documentation: github.com/google/go-github/v45/github

     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  
     6  package github
     7  
     8  import (
     9  	"context"
    10  	"fmt"
    11  )
    12  
    13  // ListProjects lists the projects for an organization.
    14  //
    15  // GitHub API docs: https://docs.github.com/en/rest/projects/projects#list-organization-projects
    16  func (s *OrganizationsService) ListProjects(ctx context.Context, org string, opts *ProjectListOptions) ([]*Project, *Response, error) {
    17  	u := fmt.Sprintf("orgs/%v/projects", org)
    18  	u, err := addOptions(u, opts)
    19  	if err != nil {
    20  		return nil, nil, err
    21  	}
    22  
    23  	req, err := s.client.NewRequest("GET", u, nil)
    24  	if err != nil {
    25  		return nil, nil, err
    26  	}
    27  
    28  	// TODO: remove custom Accept header when this API fully launches.
    29  	req.Header.Set("Accept", mediaTypeProjectsPreview)
    30  
    31  	var projects []*Project
    32  	resp, err := s.client.Do(ctx, req, &projects)
    33  	if err != nil {
    34  		return nil, resp, err
    35  	}
    36  
    37  	return projects, resp, nil
    38  }
    39  
    40  // CreateProject creates a GitHub Project for the specified organization.
    41  //
    42  // GitHub API docs: https://docs.github.com/en/rest/projects/projects#create-an-organization-project
    43  func (s *OrganizationsService) CreateProject(ctx context.Context, org string, opts *ProjectOptions) (*Project, *Response, error) {
    44  	u := fmt.Sprintf("orgs/%v/projects", org)
    45  	req, err := s.client.NewRequest("POST", u, opts)
    46  	if err != nil {
    47  		return nil, nil, err
    48  	}
    49  
    50  	// TODO: remove custom Accept header when this API fully launches.
    51  	req.Header.Set("Accept", mediaTypeProjectsPreview)
    52  
    53  	project := &Project{}
    54  	resp, err := s.client.Do(ctx, req, project)
    55  	if err != nil {
    56  		return nil, resp, err
    57  	}
    58  
    59  	return project, resp, nil
    60  }
    61  

View as plain text