-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add ProjectsService #3718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JoannaaKL
wants to merge
38
commits into
google:master
Choose a base branch
from
JoannaaKL:add-projects
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+917
−29
Open
Add ProjectsService #3718
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
775f0f6
Add support for projects V2
JoannaaKL 74712bd
Add test
JoannaaKL 3a8cf0c
Address feedback
JoannaaKL b754eeb
Merge branch 'master' into add-projects
JoannaaKL e93ed36
Remove header and rename functions
JoannaaKL 99852cf
Update comments
JoannaaKL 7664215
Copyright update
JoannaaKL 89016d9
Merge branch 'master' into add-projects
JoannaaKL 2b94765
Update comments
JoannaaKL a4b0a56
Generate docs
JoannaaKL 696102b
Add list projects option
JoannaaKL 469e03a
Generate openapi docs
JoannaaKL 2dbe5b4
Results of generate
JoannaaKL 478ef5a
Merge branch 'master' into add-projects
JoannaaKL c34802d
Merge branch 'master' into add-projects
JoannaaKL 053a9e1
Update github/projects.go
JoannaaKL 680a0d1
Rename url in test
JoannaaKL d8696b4
Generate again
JoannaaKL 93dd34f
Merge branch 'master' into add-projects
JoannaaKL 060aaae
Shorten functions for orgs
JoannaaKL 65e64f7
Change ID type from string to int
JoannaaKL d300550
Extract pagination options for projects
JoannaaKL fc5d3cb
Remove comments
JoannaaKL 9d6bf4b
Merge branch 'master' into add-projects
JoannaaKL 9f4c89d
Merge branch 'master' into add-projects
JoannaaKL 3dd69be
Merge branch 'master' into add-projects
JoannaaKL 275f930
Update github/projects.go
JoannaaKL aca15c0
Sync openapi_operations.yaml
JoannaaKL 8ee5bc4
Merge branch 'master' into add-projects
JoannaaKL 0ca0521
Address pr comments
JoannaaKL fb6e7a8
Add integration test and minor tweaks
JoannaaKL 6d0637f
Merge branch 'master' into add-projects
JoannaaKL 5cc797e
.
JoannaaKL c6cfe31
Update test/integration/projects_test.go
JoannaaKL c9feeb2
Update test/integration/projects_test.go
JoannaaKL 8c985a9
Update test/integration/projects_test.go
JoannaaKL 1625c61
Update test/integration/projects_test.go
JoannaaKL a11a2fa
Merge branch 'master' into add-projects
JoannaaKL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,218 @@ | ||
// Copyright 2025 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" | ||
) | ||
|
||
// ProjectsService handles communication with the project V2 | ||
// methods of the GitHub API. | ||
// | ||
// GitHub API docs: https://docs.github.com/rest/projects/projects | ||
type ProjectsService service | ||
|
||
// ProjectV2 represents a v2 project. | ||
type ProjectV2 struct { | ||
ID *int64 `json:"id,omitempty"` | ||
NodeID *string `json:"node_id,omitempty"` | ||
Owner *User `json:"owner,omitempty"` | ||
Creator *User `json:"creator,omitempty"` | ||
Title *string `json:"title,omitempty"` | ||
Description *string `json:"description,omitempty"` | ||
Public *bool `json:"public,omitempty"` | ||
ClosedAt *Timestamp `json:"closed_at,omitempty"` | ||
CreatedAt *Timestamp `json:"created_at,omitempty"` | ||
UpdatedAt *Timestamp `json:"updated_at,omitempty"` | ||
DeletedAt *Timestamp `json:"deleted_at,omitempty"` | ||
Number *int `json:"number,omitempty"` | ||
ShortDescription *string `json:"short_description,omitempty"` | ||
DeletedBy *User `json:"deleted_by,omitempty"` | ||
|
||
// Fields migrated from the Project (classic) struct: | ||
URL *string `json:"url,omitempty"` | ||
HTMLURL *string `json:"html_url,omitempty"` | ||
ColumnsURL *string `json:"columns_url,omitempty"` | ||
OwnerURL *string `json:"owner_url,omitempty"` | ||
Name *string `json:"name,omitempty"` | ||
Body *string `json:"body,omitempty"` | ||
State *string `json:"state,omitempty"` | ||
OrganizationPermission *string `json:"organization_permission,omitempty"` | ||
Private *bool `json:"private,omitempty"` | ||
} | ||
|
||
func (p ProjectV2) String() string { return Stringify(p) } | ||
|
||
// ListProjectsPaginationOptions specifies optional parameters to list projects for user / organization. | ||
// | ||
// Note: Pagination is powered by before/after cursor-style pagination. After the initial call, | ||
// inspect the returned *Response. Use resp.After as the opts.After value to request | ||
// the next page, and resp.Before as the opts.Before value to request the previous | ||
// page. Set either Before or After for a request; if both are | ||
// supplied GitHub API will return an error. PerPage controls the number of items | ||
// per page (max 100 per GitHub API docs). | ||
type ListProjectsPaginationOptions struct { | ||
// A cursor, as given in the Link header. If specified, the query only searches for events before this cursor. | ||
Before string `url:"before,omitempty"` | ||
|
||
// A cursor, as given in the Link header. If specified, the query only searches for events after this cursor. | ||
After string `url:"after,omitempty"` | ||
|
||
// For paginated result sets, the number of results to include per page. | ||
PerPage int `url:"per_page,omitempty"` | ||
} | ||
|
||
// ListProjectsOptions specifies optional parameters to list projects for user / organization. | ||
type ListProjectsOptions struct { | ||
ListProjectsPaginationOptions | ||
|
||
// Q is an optional query string to limit results to projects of the specified type. | ||
Query string `url:"q,omitempty"` | ||
} | ||
|
||
// ProjectV2FieldOption represents an option for a project field of type single_select or multi_select. | ||
// It defines the available choices that can be selected for dropdown-style fields. | ||
// | ||
// GitHub API docs: https://docs.github.com/rest/projects/fields | ||
type ProjectV2FieldOption struct { | ||
ID string `json:"id,omitempty"` | ||
// The display name of the option. | ||
Name string `json:"name,omitempty"` | ||
// The color associated with this option (e.g., "blue", "red"). | ||
Color string `json:"color,omitempty"` | ||
// An optional description for this option. | ||
Description string `json:"description,omitempty"` | ||
} | ||
|
||
// ProjectV2Field represents a field in a GitHub Projects V2 project. | ||
// Fields define the structure and data types for project items. | ||
// | ||
// GitHub API docs: https://docs.github.com/rest/projects/fields | ||
type ProjectV2Field struct { | ||
ID *int64 `json:"id,omitempty"` | ||
NodeID string `json:"node_id,omitempty"` | ||
Name string `json:"name,omitempty"` | ||
DataType string `json:"dataType,omitempty"` | ||
URL string `json:"url,omitempty"` | ||
Options []*any `json:"options,omitempty"` | ||
CreatedAt *Timestamp `json:"created_at,omitempty"` | ||
UpdatedAt *Timestamp `json:"updated_at,omitempty"` | ||
} | ||
|
||
// ListProjectsForOrg lists Projects V2 for an organization. | ||
// | ||
// GitHub API docs: https://docs.github.com/rest/projects/projects#list-projects-for-organization | ||
// | ||
//meta:operation GET /orgs/{org}/projectsV2 | ||
func (s *ProjectsService) ListProjectsForOrg(ctx context.Context, org string, opts *ListProjectsOptions) ([]*ProjectV2, *Response, error) { | ||
u := fmt.Sprintf("orgs/%v/projectsV2", org) | ||
u, err := addOptions(u, opts) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
req, err := s.client.NewRequest("GET", u, nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
var projects []*ProjectV2 | ||
resp, err := s.client.Do(ctx, req, &projects) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
return projects, resp, nil | ||
} | ||
|
||
// GetProjectForOrg gets a Projects V2 project for an organization by ID. | ||
// | ||
// GitHub API docs: https://docs.github.com/rest/projects/projects#get-project-for-organization | ||
// | ||
//meta:operation GET /orgs/{org}/projectsV2/{project_number} | ||
func (s *ProjectsService) GetProjectForOrg(ctx context.Context, org string, projectNumber int) (*ProjectV2, *Response, error) { | ||
u := fmt.Sprintf("orgs/%v/projectsV2/%v", org, projectNumber) | ||
req, err := s.client.NewRequest("GET", u, nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
project := new(ProjectV2) | ||
resp, err := s.client.Do(ctx, req, project) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
return project, resp, nil | ||
} | ||
|
||
// ListProjectsForUser lists Projects V2 for a user. | ||
// | ||
// GitHub API docs: https://docs.github.com/rest/projects/projects#list-projects-for-user | ||
// | ||
//meta:operation GET /users/{username}/projectsV2 | ||
func (s *ProjectsService) ListProjectsForUser(ctx context.Context, username string, opts *ListProjectsOptions) ([]*ProjectV2, *Response, error) { | ||
u := fmt.Sprintf("users/%v/projectsV2", username) | ||
u, err := addOptions(u, opts) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
req, err := s.client.NewRequest("GET", u, nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
var projects []*ProjectV2 | ||
resp, err := s.client.Do(ctx, req, &projects) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
return projects, resp, nil | ||
} | ||
|
||
// GetProjectForUser gets a Projects V2 project for a user by ID. | ||
// | ||
// GitHub API docs: https://docs.github.com/rest/projects/projects#get-project-for-user | ||
// | ||
//meta:operation GET /users/{username}/projectsV2/{project_number} | ||
func (s *ProjectsService) GetProjectForUser(ctx context.Context, username string, projectNumber int) (*ProjectV2, *Response, error) { | ||
u := fmt.Sprintf("users/%v/projectsV2/%v", username, projectNumber) | ||
req, err := s.client.NewRequest("GET", u, nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
project := new(ProjectV2) | ||
resp, err := s.client.Do(ctx, req, project) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
return project, resp, nil | ||
} | ||
|
||
// ListProjectFieldsForOrg lists Projects V2 for an organization. | ||
// | ||
// GitHub API docs: https://docs.github.com/rest/projects/fields#list-project-fields-for-organization | ||
// | ||
//meta:operation GET /orgs/{org}/projectsV2/{project_number}/fields | ||
func (s *ProjectsService) ListProjectFieldsForOrg(ctx context.Context, org string, projectNumber int, opts *ListProjectsOptions) ([]*ProjectV2Field, *Response, error) { | ||
u := fmt.Sprintf("orgs/%v/projectsV2/%v/fields", org, projectNumber) | ||
u, err := addOptions(u, opts) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
req, err := s.client.NewRequest("GET", u, nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
var fields []*ProjectV2Field | ||
resp, err := s.client.Do(ctx, req, &fields) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
return fields, resp, nil | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.