-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Implement the actions required workflows APIs #2730
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
039e5ea
implemented the required workflow API's
avivek 114e41e
Merge branch 'master' into ActionsRequiredWorkflow
avivek d0bf3d1
fixed linting errors and renamed repository to repos in method names
avivek b316aae
Merge branch 'master' into ActionsRequiredWorkflow
avivek b682996
Apply suggestions from code review
avivek 3f371f8
Fixed Linter issues and review comments
avivek 9f479c2
Merge branch 'master' into ActionsRequiredWorkflow
avivek 4a1ad13
review comment styling
avivek 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,233 @@ | ||
// Copyright 2023 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" | ||
) | ||
|
||
// OrgRequiredWorkflow represents a required workflow object at the org level. | ||
type OrgRequiredWorkflow struct { | ||
ID *int64 `json:"id,omitempty"` | ||
Name *string `json:"name,omitempty"` | ||
Path *string `json:"path,omitempty"` | ||
Scope *string `json:"scope,omitempty"` | ||
Ref *string `json:"ref,omitempty"` | ||
State *string `json:"state,omitempty"` | ||
SelectedRepositoriesURL *string `json:"selected_repositories_url,omitempty"` | ||
CreatedAt *Timestamp `json:"created_at,omitempty"` | ||
UpdatedAt *Timestamp `json:"updated_at,omitempty"` | ||
Repository *Repository `json:"repository,omitempty"` | ||
} | ||
|
||
// OrgRequiredWorkflows represents the required workflows for the org. | ||
type OrgRequiredWorkflows struct { | ||
TotalCount *int `json:"total_count,omitempty"` | ||
RequiredWorkflows []*OrgRequiredWorkflow `json:"required_workflows,omitempty"` | ||
} | ||
|
||
// CreateUpdateRequiredWorkflowOptions represents the input object used to create or update required workflows. | ||
type CreateUpdateRequiredWorkflowOptions struct { | ||
WorkflowFilePath *string `json:"workflow_file_path,omitempty"` | ||
RepositoryID *int64 `json:"repository_id,omitempty"` | ||
Scope *string `json:"scope,omitempty"` | ||
SelectedRepositoryIDs *SelectedRepoIDs `json:"selected_repository_ids,omitempty"` | ||
} | ||
|
||
// RequiredWorkflowSelectedRepos represents the repos that a required workflow is applied to. | ||
type RequiredWorkflowSelectedRepos struct { | ||
TotalCount *int `json:"total_count,omitempty"` | ||
Repositories []*Repository `json:"repositories,omitempty"` | ||
} | ||
|
||
// RepoRequiredWorkflow represents a required workflow object at the repo level. | ||
type RepoRequiredWorkflow struct { | ||
ID *int64 `json:"id,omitempty"` | ||
NodeID *string `json:"node_id,omitempty"` | ||
Name *string `json:"name,omitempty"` | ||
Path *string `json:"path,omitempty"` | ||
State *string `json:"state,omitempty"` | ||
URL *string `json:"url,omitempty"` | ||
HTMLURL *string `json:"html_url,omitempty"` | ||
BadgeURL *string `json:"badge_url,omitempty"` | ||
CreatedAt *Timestamp `json:"created_at,omitempty"` | ||
UpdatedAt *Timestamp `json:"updated_at,omitempty"` | ||
SourceRepository *Repository `json:"source_repository,omitempty"` | ||
} | ||
|
||
// RepoRequiredWorkflows represents the required workflows for a repo. | ||
type RepoRequiredWorkflows struct { | ||
TotalCount *int `json:"total_count,omitempty"` | ||
RequiredWorkflows []*RepoRequiredWorkflow `json:"required_workflows,omitempty"` | ||
} | ||
|
||
// ListOrgRequiredWorkflows lists the RequiredWorkflows for an org. | ||
// | ||
// GitHub API docs: https://docs.github.com/en/rest/actions/required-workflows?apiVersion=2022-11-28#list-required-workflows | ||
func (s *ActionsService) ListOrgRequiredWorkflows(ctx context.Context, org string, opts *ListOptions) (*OrgRequiredWorkflows, *Response, error) { | ||
url := fmt.Sprintf("orgs/%v/actions/required_workflows", org) | ||
u, err := addOptions(url, opts) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
req, err := s.client.NewRequest("GET", u, nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
requiredWorkflows := new(OrgRequiredWorkflows) | ||
resp, err := s.client.Do(ctx, req, &requiredWorkflows) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
|
||
return requiredWorkflows, resp, nil | ||
} | ||
|
||
// CreateRequiredWorkflow creates the required workflow in an org. | ||
// | ||
// GitHub API docs: https://docs.github.com/en/rest/actions/required-workflows?apiVersion=2022-11-28#create-a-required-workflow | ||
func (s *ActionsService) CreateRequiredWorkflow(ctx context.Context, org string, createRequiredWorkflowOptions *CreateUpdateRequiredWorkflowOptions) (*Response, error) { | ||
url := fmt.Sprintf("orgs/%v/actions/required_workflows", org) | ||
req, err := s.client.NewRequest("PUT", url, createRequiredWorkflowOptions) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return s.client.Do(ctx, req, nil) | ||
} | ||
|
||
// GetRequiredWorkflowByID get the RequiredWorkflows for an org by its ID. | ||
// | ||
// GitHub API docs: https://docs.github.com/en/rest/actions/required-workflows?apiVersion=2022-11-28#list-required-workflows | ||
func (s *ActionsService) GetRequiredWorkflowByID(ctx context.Context, owner string, requiredWorkflowID int64) (*OrgRequiredWorkflow, *Response, error) { | ||
u := fmt.Sprintf("orgs/%v/actions/required_workflows/%v", owner, requiredWorkflowID) | ||
|
||
req, err := s.client.NewRequest("GET", u, nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
requiredWorkflow := new(OrgRequiredWorkflow) | ||
resp, err := s.client.Do(ctx, req, &requiredWorkflow) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
|
||
return requiredWorkflow, resp, nil | ||
} | ||
|
||
// UpdateRequiredWorkflow updates a required workflow in an org. | ||
// | ||
// GitHub API docs: https://docs.github.com/en/rest/actions/required-workflows?apiVersion=2022-11-28#update-a-required-workflow | ||
func (s *ActionsService) UpdateRequiredWorkflow(ctx context.Context, org string, requiredWorkflowID int64, updateRequiredWorkflowOptions *CreateUpdateRequiredWorkflowOptions) (*Response, error) { | ||
url := fmt.Sprintf("orgs/%v/actions/required_workflows/%v", org, requiredWorkflowID) | ||
req, err := s.client.NewRequest("PATCH", url, updateRequiredWorkflowOptions) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return s.client.Do(ctx, req, nil) | ||
} | ||
|
||
// DeleteRequiredWorkflow deletes a required workflow in an org. | ||
// | ||
// GitHub API docs: https://docs.github.com/en/rest/actions/required-workflows?apiVersion=2022-11-28#update-a-required-workflow | ||
func (s *ActionsService) DeleteRequiredWorkflow(ctx context.Context, org string, requiredWorkflowID int64) (*Response, error) { | ||
url := fmt.Sprintf("orgs/%v/actions/required_workflows/%v", org, requiredWorkflowID) | ||
req, err := s.client.NewRequest("DELETE", url, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return s.client.Do(ctx, req, nil) | ||
} | ||
|
||
// ListRequiredWorkflowSelectedRepos lists the Repositories selected for a workflow. | ||
// | ||
// GitHub API docs: https://docs.github.com/en/rest/actions/required-workflows?apiVersion=2022-11-28#list-selected-repositories-for-a-required-workflow | ||
func (s *ActionsService) ListRequiredWorkflowSelectedRepos(ctx context.Context, org string, requiredWorkflowID int64, opts *ListOptions) (*RequiredWorkflowSelectedRepos, *Response, error) { | ||
url := fmt.Sprintf("orgs/%v/actions/required_workflows/%v/repositories", org, requiredWorkflowID) | ||
u, err := addOptions(url, opts) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
req, err := s.client.NewRequest("GET", u, nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
requiredWorkflowRepos := new(RequiredWorkflowSelectedRepos) | ||
resp, err := s.client.Do(ctx, req, &requiredWorkflowRepos) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
|
||
return requiredWorkflowRepos, resp, nil | ||
} | ||
|
||
// SetRequiredWorkflowSelectedRepos sets the Repositories selected for a workflow. | ||
// | ||
// GitHub API docs: https://docs.github.com/en/rest/actions/required-workflows?apiVersion=2022-11-28#sets-repositories-for-a-required-workflow | ||
func (s *ActionsService) SetRequiredWorkflowSelectedRepos(ctx context.Context, org string, requiredWorkflowID int64, ids SelectedRepoIDs) (*Response, error) { | ||
type repoIDs struct { | ||
SelectedIDs SelectedRepoIDs `json:"selected_repository_ids"` | ||
} | ||
url := fmt.Sprintf("orgs/%v/actions/required_workflows/%v/repositories", org, requiredWorkflowID) | ||
req, err := s.client.NewRequest("PUT", url, repoIDs{SelectedIDs: ids}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return s.client.Do(ctx, req, nil) | ||
} | ||
|
||
// AddRepoToRequiredWorkflow adds the Repository to a required workflow. | ||
// | ||
// GitHub API docs: https://docs.github.com/en/rest/actions/required-workflows?apiVersion=2022-11-28#add-a-repository-to-a-required-workflow | ||
func (s *ActionsService) AddRepoToRequiredWorkflow(ctx context.Context, org string, requiredWorkflowID, repoID int64) (*Response, error) { | ||
url := fmt.Sprintf("orgs/%v/actions/required_workflows/%v/repositories/%v", org, requiredWorkflowID, repoID) | ||
req, err := s.client.NewRequest("PUT", url, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return s.client.Do(ctx, req, nil) | ||
} | ||
|
||
// RemoveRepoFromRequiredWorkflow removes the Repository from a required workflow. | ||
// | ||
// GitHub API docs: https://docs.github.com/en/rest/actions/required-workflows?apiVersion=2022-11-28#add-a-repository-to-a-required-workflow | ||
func (s *ActionsService) RemoveRepoFromRequiredWorkflow(ctx context.Context, org string, requiredWorkflowID, repoID int64) (*Response, error) { | ||
url := fmt.Sprintf("orgs/%v/actions/required_workflows/%v/repositories/%v", org, requiredWorkflowID, repoID) | ||
req, err := s.client.NewRequest("DELETE", url, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return s.client.Do(ctx, req, nil) | ||
} | ||
|
||
// ListRepoRequiredWorkflows lists the RequiredWorkflows for a repo. | ||
// | ||
// Github API docs:https://docs.github.com/en/rest/actions/required-workflows?apiVersion=2022-11-28#list-repository-required-workflows | ||
func (s *ActionsService) ListRepoRequiredWorkflows(ctx context.Context, owner, repo string, opts *ListOptions) (*RepoRequiredWorkflows, *Response, error) { | ||
url := fmt.Sprintf("repos/%v/%v/actions/required_workflows", owner, repo) | ||
u, err := addOptions(url, opts) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
req, err := s.client.NewRequest("GET", u, nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
requiredWorkflows := new(RepoRequiredWorkflows) | ||
resp, err := s.client.Do(ctx, req, &requiredWorkflows) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
|
||
return requiredWorkflows, resp, nil | ||
} |
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.