Skip to content

Commit

Permalink
atlasaction: move github client to internal package
Browse files Browse the repository at this point in the history
  • Loading branch information
giautm committed Dec 25, 2024
1 parent 3bbfc13 commit b6332cc
Show file tree
Hide file tree
Showing 4 changed files with 416 additions and 350 deletions.
14 changes: 11 additions & 3 deletions atlasaction/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -1044,18 +1044,26 @@ func (tc *TriggerContext) SCMClient() (SCMClient, error) {
if token == "" {
tc.Act.Warningf("GITHUB_TOKEN is not set, the action may not have all the permissions")
}
return githubClient(tc.Repo, tc.SCM.APIURL, token), nil
return GitHubClient(tc.Repo, tc.SCM.APIURL, token)
case atlasexec.SCMTypeGitlab:
token := tc.Act.Getenv("GITLAB_TOKEN")
if token == "" {
tc.Act.Warningf("GITLAB_TOKEN is not set, the action may not have all the permissions")
}
return gitlabClient(tc.Act.Getenv("CI_PROJECT_ID"), tc.SCM.APIURL, token), nil
return gitlabClient(
tc.Act.Getenv("CI_PROJECT_ID"),
tc.SCM.APIURL,
token,
), nil
case atlasexec.SCMTypeBitbucket:
token := tc.Act.Getenv("BITBUCKET_ACCESS_TOKEN")
if token == "" {
tc.Act.Warningf("BITBUCKET_ACCESS_TOKEN is not set, the action may not have all the permissions")
}
return BitbucketClient(
tc.Act.Getenv("BITBUCKET_WORKSPACE"),
tc.Act.Getenv("BITBUCKET_REPO_SLUG"),
tc.Act.Getenv("BITBUCKET_ACCESS_TOKEN"),
token,
)
default:
return nil, ErrNoSCM // Not implemented yet.
Expand Down
13 changes: 10 additions & 3 deletions atlasaction/circleci_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,19 @@ func (a *circleCIOrb) GetTriggerContext(ctx context.Context) (*TriggerContext, e
tc.Branch = tag
return tc, nil
}
c := githubClient(tc.Repo, tc.SCM.APIURL, ghToken)
var err error
tc.PullRequest, err = c.OpeningPullRequest(ctx, tc.Branch)
c, err := GitHubClient(tc.Repo, tc.SCM.APIURL, ghToken)
if err != nil {
return nil, fmt.Errorf("failed to create GitHub client: %w", err)
}
pr, err := c.OpeningPullRequest(ctx, tc.Branch)
if err != nil {
return nil, fmt.Errorf("failed to get open pull requests: %w", err)
}
tc.PullRequest = &PullRequest{
Number: pr.Number,
URL: pr.URL,
Commit: pr.Commit,
}
}
return tc, nil
}
Loading

0 comments on commit b6332cc

Please sign in to comment.