Skip to content

Commit

Permalink
change: use projectID env for gitlab-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrard-YNWA committed Aug 9, 2021
1 parent c8a137c commit 0093759
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
18 changes: 13 additions & 5 deletions cienv/cienv.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ type BuildInfo struct {
// Gerrit related params
GerritChangeID string
GerritRevisionID string

// Gitlab projectID
GitlabProjectID string
}

// GetBuildInfo returns BuildInfo from environment variables.
Expand Down Expand Up @@ -91,14 +94,19 @@ func GetBuildInfo() (prInfo *BuildInfo, isPR bool, err error) {
"BITBUCKET_BRANCH",
})

projectId := getOneEnvValue([]string{
"CI_PROJECT_ID",
})

pr := getPullRequestNum()

return &BuildInfo{
Owner: owner,
Repo: repo,
PullRequest: pr,
SHA: sha,
Branch: branch,
Owner: owner,
Repo: repo,
PullRequest: pr,
SHA: sha,
Branch: branch,
GitlabProjectID: projectId,
}, pr != 0, nil
}

Expand Down
10 changes: 5 additions & 5 deletions cmd/reviewdog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,13 @@ github-pr-check reporter as a fallback.
return nil
}

gc, err := gitlabservice.NewGitLabMergeRequestDiscussionCommenter(cli, build.Owner, build.Repo, build.PullRequest, build.SHA)
gc, err := gitlabservice.NewGitLabMergeRequestDiscussionCommenter(cli, build.GitlabProjectID, build.PullRequest, build.SHA)
if err != nil {
return err
}

cs = reviewdog.MultiCommentService(gc, cs)
ds, err = gitlabservice.NewGitLabMergeRequestDiff(cli, build.Owner, build.Repo, build.PullRequest, build.SHA)
ds, err = gitlabservice.NewGitLabMergeRequestDiff(cli, build.GitlabProjectID, build.PullRequest, build.SHA)
if err != nil {
return err
}
Expand All @@ -321,13 +321,13 @@ github-pr-check reporter as a fallback.
return nil
}

gc, err := gitlabservice.NewGitLabMergeRequestCommitCommenter(cli, build.Owner, build.Repo, build.PullRequest, build.SHA)
gc, err := gitlabservice.NewGitLabMergeRequestCommitCommenter(cli, build.GitlabProjectID, build.PullRequest, build.SHA)
if err != nil {
return err
}

cs = reviewdog.MultiCommentService(gc, cs)
ds, err = gitlabservice.NewGitLabMergeRequestDiff(cli, build.Owner, build.Repo, build.PullRequest, build.SHA)
ds, err = gitlabservice.NewGitLabMergeRequestDiff(cli, build.GitlabProjectID, build.PullRequest, build.SHA)
if err != nil {
return err
}
Expand Down Expand Up @@ -571,7 +571,7 @@ func gitlabBuildWithClient() (*cienv.BuildInfo, *gitlab.Client, error) {
}

if g.PullRequest == 0 {
prNr, err := fetchMergeRequestIDFromCommit(client, g.Owner+"/"+g.Repo, g.SHA)
prNr, err := fetchMergeRequestIDFromCommit(client, g.GitlabProjectID, g.SHA)
if err != nil {
return nil, nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions service/gitlab/gitlab_mr_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type MergeRequestCommitCommenter struct {

// NewGitLabMergeRequestCommitCommenter returns a new MergeRequestCommitCommenter service.
// MergeRequestCommitCommenter service needs git command in $PATH.
func NewGitLabMergeRequestCommitCommenter(cli *gitlab.Client, owner, repo string, pr int, sha string) (*MergeRequestCommitCommenter, error) {
func NewGitLabMergeRequestCommitCommenter(cli *gitlab.Client, projectID string, pr int, sha string) (*MergeRequestCommitCommenter, error) {
workDir, err := serviceutil.GitRelWorkdir()
if err != nil {
return nil, fmt.Errorf("MergeRequestCommitCommenter needs 'git' command: %w", err)
Expand All @@ -49,7 +49,7 @@ func NewGitLabMergeRequestCommitCommenter(cli *gitlab.Client, owner, repo string
cli: cli,
pr: pr,
sha: sha,
projects: owner + "/" + repo,
projects: projectID,
wd: workDir,
}, nil
}
Expand Down
4 changes: 2 additions & 2 deletions service/gitlab/gitlab_mr_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type MergeRequestDiff struct {

// NewGitLabMergeRequestDiff returns a new MergeRequestDiff service.
// itLabMergeRequestDiff service needs git command in $PATH.
func NewGitLabMergeRequestDiff(cli *gitlab.Client, owner, repo string, pr int, sha string) (*MergeRequestDiff, error) {
func NewGitLabMergeRequestDiff(cli *gitlab.Client, projectID string, pr int, sha string) (*MergeRequestDiff, error) {
workDir, err := serviceutil.GitRelWorkdir()
if err != nil {
return nil, fmt.Errorf("MergeRequestCommitCommenter needs 'git' command: %w", err)
Expand All @@ -36,7 +36,7 @@ func NewGitLabMergeRequestDiff(cli *gitlab.Client, owner, repo string, pr int, s
cli: cli,
pr: pr,
sha: sha,
projects: owner + "/" + repo,
projects: projectID,
wd: workDir,
}, nil
}
Expand Down
4 changes: 2 additions & 2 deletions service/gitlab/gitlab_mr_discussion.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type MergeRequestDiscussionCommenter struct {

// NewGitLabMergeRequestDiscussionCommenter returns a new MergeRequestDiscussionCommenter service.
// MergeRequestDiscussionCommenter service needs git command in $PATH.
func NewGitLabMergeRequestDiscussionCommenter(cli *gitlab.Client, owner, repo string, pr int, sha string) (*MergeRequestDiscussionCommenter, error) {
func NewGitLabMergeRequestDiscussionCommenter(cli *gitlab.Client, projectID string, pr int, sha string) (*MergeRequestDiscussionCommenter, error) {
workDir, err := serviceutil.GitRelWorkdir()
if err != nil {
return nil, fmt.Errorf("MergeRequestDiscussionCommenter needs 'git' command: %w", err)
Expand All @@ -51,7 +51,7 @@ func NewGitLabMergeRequestDiscussionCommenter(cli *gitlab.Client, owner, repo st
cli: cli,
pr: pr,
sha: sha,
projects: owner + "/" + repo,
projects: projectID,
wd: workDir,
}, nil
}
Expand Down

0 comments on commit 0093759

Please sign in to comment.