Skip to content

Commit

Permalink
Is that good enough memoization?
Browse files Browse the repository at this point in the history
  • Loading branch information
Edvard Makhlin committed May 7, 2024
1 parent 3d73c92 commit 0f1472f
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions server/events/vcs/bitbucketcloud/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func NewClient(httpClient *http.Client, username string, password string, atlant
}
}

var MY_UUID = ""

// GetModifiedFiles returns the names of files that were modified in the merge request
// relative to the repo root, e.g. parent/child/file.txt.
func (b *Client) GetModifiedFiles(logger logging.SimpleLogging, repo models.Repo, pull models.PullRequest) ([]string, error) {
Expand Down Expand Up @@ -165,25 +167,30 @@ func (b *Client) GetPullRequestComments(repo models.Repo, pullNum int) (comments
}

func (b *Client) GetMyUUID() (uuid string, err error) {
path := fmt.Sprintf("%s/2.0/user", b.BaseURL)
resp, err := b.makeRequest("GET", path, nil)
if MY_UUID == "" {
path := fmt.Sprintf("%s/2.0/user", b.BaseURL)
resp, err := b.makeRequest("GET", path, nil)

if err != nil {
return uuid, err
}
if err != nil {
return uuid, err
}

var user User
if err := json.Unmarshal(resp, &user); err != nil {
return uuid, errors.Wrapf(err, "Could not parse response %q", string(resp))
}
var user User
if err := json.Unmarshal(resp, &user); err != nil {
return uuid, errors.Wrapf(err, "Could not parse response %q", string(resp))
}

if err := validator.New().Struct(user); err != nil {
return uuid, errors.Wrapf(err, "API response %q was missing a field", string(resp))
}
if err := validator.New().Struct(user); err != nil {
return uuid, errors.Wrapf(err, "API response %q was missing a field", string(resp))
}

uuid = *user.UUID
return uuid, nil
uuid = *user.UUID
MY_UUID = uuid

return uuid, nil
} else {
return MY_UUID, nil
}
}

// PullIsApproved returns true if the merge request was approved.
Expand Down

0 comments on commit 0f1472f

Please sign in to comment.