-
Notifications
You must be signed in to change notification settings - Fork 458
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add RepoClient API for ListCheckRunsForRef (#948)
Co-authored-by: Azeem Shaikh <azeems@google.com>
- Loading branch information
1 parent
8f5e742
commit eb2b3b2
Showing
7 changed files
with
133 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2021 Security Scorecard Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package clients | ||
|
||
// CheckRun is a single instance of a VCS CheckRun. | ||
type CheckRun struct { | ||
Status string | ||
Conclusion string | ||
URL string | ||
App CheckRunApp | ||
} | ||
|
||
// CheckRunApp is the app running the Check. | ||
type CheckRunApp struct { | ||
Slug string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2021 Security Scorecard Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package githubrepo | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/google/go-github/v38/github" | ||
|
||
"github.com/ossf/scorecard/v2/clients" | ||
sce "github.com/ossf/scorecard/v2/errors" | ||
) | ||
|
||
type checkrunsHandler struct { | ||
client *github.Client | ||
ctx context.Context | ||
owner string | ||
repo string | ||
} | ||
|
||
func (handler *checkrunsHandler) init(ctx context.Context, owner, repo string) { | ||
handler.ctx = ctx | ||
handler.owner = owner | ||
handler.repo = repo | ||
} | ||
|
||
func (handler *checkrunsHandler) listCheckRunsForRef(ref string) ([]clients.CheckRun, error) { | ||
checkRuns, _, err := handler.client.Checks.ListCheckRunsForRef(handler.ctx, handler.owner, handler.repo, ref, | ||
&github.ListCheckRunsOptions{}) | ||
if err != nil { | ||
// nolint: wrapcheck | ||
return nil, sce.Create(sce.ErrScorecardInternal, fmt.Sprintf("ListCheckRunsForRef: %v", err)) | ||
} | ||
return checkRunsFrom(checkRuns), nil | ||
} | ||
|
||
func checkRunsFrom(data *github.ListCheckRunsResults) []clients.CheckRun { | ||
// nolint: prealloc // https://github.com/golang/go/wiki/CodeReviewComments#declaring-empty-slices | ||
var checkRuns []clients.CheckRun | ||
for _, checkRun := range data.CheckRuns { | ||
checkRuns = append(checkRuns, clients.CheckRun{ | ||
Status: checkRun.GetStatus(), | ||
Conclusion: checkRun.GetConclusion(), | ||
URL: checkRun.GetURL(), | ||
App: clients.CheckRunApp{ | ||
Slug: checkRun.GetApp().GetSlug(), | ||
}, | ||
}) | ||
} | ||
return checkRuns | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters