Skip to content

Commit

Permalink
fix client issues
Browse files Browse the repository at this point in the history
  • Loading branch information
djeebus committed Feb 27, 2024
1 parent f4c11e8 commit 0a73e21
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pkg/vcs/gitlab_client/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (c *Client) GetMergeChanges(ctx context.Context, projectId int, mergeReqId
defer span.End()

var changes []*Changes
diffs, _, err := c.MergeRequests.ListMergeRequestDiffs(projectId, mergeReqId, &gitlab.ListMergeRequestDiffsOptions{})
diffs, _, err := c.c.MergeRequests.ListMergeRequestDiffs(projectId, mergeReqId, &gitlab.ListMergeRequestDiffsOptions{})
if err != nil {
telemetry.SetError(span, err, "Get MergeRequest Changes")
return changes, err
Expand Down
12 changes: 6 additions & 6 deletions pkg/vcs/gitlab_client/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (c *Client) PostMessage(ctx context.Context, repo *vcs.Repo, mergeRequestID
message = message[:MaxCommentLength]
}

n, _, err := c.Notes.CreateMergeRequestNote(
n, _, err := c.c.Notes.CreateMergeRequestNote(
repo.FullName, mergeRequestID,
&gitlab.CreateMergeRequestNoteOptions{
Body: pkg.Pointer(message),
Expand Down Expand Up @@ -71,7 +71,7 @@ func (c *Client) hideOutdatedMessages(ctx context.Context, projectName string, m

log.Debug().Str("projectName", projectName).Int("mr", mergeRequestID).Msgf("Updating comment %d as outdated", note.ID)

_, _, err := c.Notes.UpdateMergeRequestNote(projectName, mergeRequestID, note.ID, &gitlab.UpdateMergeRequestNoteOptions{
_, _, err := c.c.Notes.UpdateMergeRequestNote(projectName, mergeRequestID, note.ID, &gitlab.UpdateMergeRequestNoteOptions{
Body: &newBody,
})

Expand All @@ -92,7 +92,7 @@ func (c *Client) UpdateMessage(ctx context.Context, m *msg.Message, message stri
message = message[:MaxCommentLength]
}

n, _, err := c.Notes.UpdateMergeRequestNote(m.Name, m.CheckID, m.NoteID, &gitlab.UpdateMergeRequestNoteOptions{
n, _, err := c.c.Notes.UpdateMergeRequestNote(m.Name, m.CheckID, m.NoteID, &gitlab.UpdateMergeRequestNoteOptions{
Body: pkg.Pointer(message),
})

Expand All @@ -116,7 +116,7 @@ func (c *Client) pruneOldComments(ctx context.Context, projectName string, mrID
for _, note := range notes {
if note.Author.Username == c.username {
log.Debug().Int("mr", mrID).Int("note", note.ID).Msg("deleting old comment")
_, err := c.Notes.DeleteMergeRequestNote(projectName, mrID, note.ID)
_, err := c.c.Notes.DeleteMergeRequestNote(projectName, mrID, note.ID)
if err != nil {
telemetry.SetError(span, err, "Prune Old Comments")
return fmt.Errorf("could not delete old comment: %w", err)
Expand All @@ -137,7 +137,7 @@ func (c *Client) TidyOutdatedComments(ctx context.Context, repo *vcs.Repo) error

for {
// list merge request notes
notes, resp, err := c.Notes.ListMergeRequestNotes(repo.FullName, repo.CheckID, &gitlab.ListMergeRequestNotesOptions{
notes, resp, err := c.c.Notes.ListMergeRequestNotes(repo.FullName, repo.CheckID, &gitlab.ListMergeRequestNotesOptions{
Sort: pkg.Pointer("asc"),
OrderBy: pkg.Pointer("created_at"),
ListOptions: gitlab.ListOptions{
Expand All @@ -156,7 +156,7 @@ func (c *Client) TidyOutdatedComments(ctx context.Context, repo *vcs.Repo) error
nextPage = resp.NextPage
}

if strings.ToLower(c.tidyOutdatedCommentsMode) == "delete" {
if strings.ToLower(c.cfg.TidyOutdatedCommentsMode) == "delete" {
return c.pruneOldComments(ctx, repo.FullName, repo.CheckID, allNotes)
}
return c.hideOutdatedMessages(ctx, repo.FullName, repo.CheckID, allNotes)
Expand Down
2 changes: 1 addition & 1 deletion pkg/vcs/gitlab_client/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func (c *Client) GetPipelinesForCommit(projectName string, commitSHA string) ([]*gitlab.PipelineInfo, error) {
pipelines, _, err := c.Pipelines.ListProjectPipelines(projectName, &gitlab.ListProjectPipelinesOptions{
pipelines, _, err := c.c.Pipelines.ListProjectPipelines(projectName, &gitlab.ListProjectPipelinesOptions{
SHA: pkg.Pointer(commitSHA),
})
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/vcs/gitlab_client/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import (
"github.com/zapier/kubechecks/pkg/repo_config"
)

// GetProjectByIDorName gets a project by the given Project Name or ID
// GetProjectByID gets a project by the given Project Name or ID
func (c *Client) GetProjectByID(project int) (*gitlab.Project, error) {
var proj *gitlab.Project
err := backoff.Retry(func() error {
var err error
var resp *gitlab.Response
proj, resp, err = c.Projects.GetProject(project, nil)
proj, resp, err = c.c.Projects.GetProject(project, nil)
return checkReturnForBackoff(resp, err)
}, getBackOff())
return proj, err
Expand All @@ -30,7 +30,7 @@ func (c *Client) GetRepoConfigFile(ctx context.Context, projectId int, mergeReqI

// check MR branch
for _, file := range repo_config.RepoConfigFilenameVariations() {
b, _, err := c.RepositoryFiles.GetRawFile(
b, _, err := c.c.RepositoryFiles.GetRawFile(
projectId,
file,
&gitlab.GetRawFileOptions{Ref: pkg.Pointer("HEAD")},
Expand Down
2 changes: 1 addition & 1 deletion pkg/vcs/gitlab_client/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func convertState(state pkg.CommitState) gitlab.BuildStateValue {
}

func (c *Client) setCommitStatus(projectWithNS string, commitSHA string, status *gitlab.SetCommitStatusOptions) (*gitlab.CommitStatus, error) {
commitStatus, _, err := c.Commits.SetCommitStatus(projectWithNS, commitSHA, status)
commitStatus, _, err := c.c.Commits.SetCommitStatus(projectWithNS, commitSHA, status)
return commitStatus, err
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/vcs/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@ func TestCensorVcsToken(t *testing.T) {
func TestCensorEmptyVcsToken(t *testing.T) {
cfg := config.ServerConfig{VcsToken: ""}
result := censorVcsToken(cfg, []string{"one", "two", "three"})
assert.Equal(t, []string{"one", "two", "te"}, result)
assert.Equal(t, []string{"one", "two", "three"}, result)
}

0 comments on commit 0a73e21

Please sign in to comment.