From 2b3de63d8ba04df1bd4562c324e43082b3dd8c34 Mon Sep 17 00:00:00 2001 From: Omer Zidkoni <50792403+omerzi@users.noreply.github.com> Date: Sun, 30 Jul 2023 14:11:35 +0300 Subject: [PATCH] Fix golang-ci notes (#105) --- vcsclient/azurerepos.go | 8 ++++---- vcsclient/github.go | 9 ++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/vcsclient/azurerepos.go b/vcsclient/azurerepos.go index 90c3a82b..99e71f3c 100644 --- a/vcsclient/azurerepos.go +++ b/vcsclient/azurerepos.go @@ -301,7 +301,7 @@ func (client *AzureReposClient) getOpenPullRequests(ctx context.Context, owner, } var pullRequestsInfo []PullRequestInfo for _, pullRequest := range *pullRequests { - pullRequestDetails := parsePullRequestDetails(client, pullRequest, owner, repository) + pullRequestDetails := parsePullRequestDetails(client, pullRequest, owner, repository, withBody) pullRequestsInfo = append(pullRequestsInfo, pullRequestDetails) } return pullRequestsInfo, nil @@ -320,7 +320,7 @@ func (client *AzureReposClient) GetPullRequestByID(ctx context.Context, owner, r if err != nil { return } - pullRequestInfo = parsePullRequestDetails(client, *pullRequest, owner, repository) + pullRequestInfo = parsePullRequestDetails(client, *pullRequest, owner, repository, false) return } @@ -575,14 +575,14 @@ func (client *AzureReposClient) GetModifiedFiles(ctx context.Context, _, reposit return fileNamesList, nil } -func parsePullRequestDetails(client *AzureReposClient, pullRequest git.GitPullRequest, owner, repository string) PullRequestInfo { +func parsePullRequestDetails(client *AzureReposClient, pullRequest git.GitPullRequest, owner, repository string, withBody bool) PullRequestInfo { // Trim the branches prefix and get the actual branches name shortSourceName := (*pullRequest.SourceRefName)[strings.LastIndex(*pullRequest.SourceRefName, "/")+1:] shortTargetName := (*pullRequest.TargetRefName)[strings.LastIndex(*pullRequest.TargetRefName, "/")+1:] var prBody string bodyPtr := pullRequest.Description - if bodyPtr != nil { + if bodyPtr != nil && withBody { prBody = *bodyPtr } diff --git a/vcsclient/github.go b/vcsclient/github.go index 2b898c15..08efd2ff 100644 --- a/vcsclient/github.go +++ b/vcsclient/github.go @@ -620,12 +620,11 @@ func (client *GitHubClient) UploadCodeScanning(ctx context.Context, owner, repos if sarifID != nil && *sarifID.ID != "" { return *sarifID.ID, err } - aerr, ok := err.(*github.AcceptedError) var result map[string]string - if ok { - err = json.Unmarshal(aerr.Raw, &result) - if err != nil { - return "", nil + var ghAcceptedError *github.AcceptedError + if errors.As(err, &ghAcceptedError) { + if err = json.Unmarshal(ghAcceptedError.Raw, &result); err != nil { + return "", err } return result["id"], nil }