scorecard/clients/gitlabrepo/statuses.go
jimrobison 03dc18db78
🐛 Gitlab: Commit/Commitor Exceptions (#3026)
* feat: Added paging for contributor/users against gitlab projects

Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com>

* refactor: Updated the bot flag for unmatched users

Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com>

* fix: Not all commit users are in the git registry instance

Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com>

* fix: Skipping check if the email is empty, as well as if the "email" doesn't contain a "." char.

Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com>

* fix: Updated to allow for commits with PRs to be accounted/added to the client.commits

Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com>

* refactor: Updated to prevent linting issue regarding nested if's

Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com>

* test: Adding coverage for commits and contributors for gitlab

Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com>

* refactor: Moved queries from the client to their own functions

Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com>

* bug: Need to pass the ProjectID value to the contributor query

Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com>

* bug: Updating project title versus projectID values for api querying

Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com>

* test: Updated tests to match expected property set for projectID

Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com>

* revert: Reverted based on feedback during review

Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com>

---------

Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com>
2023-05-19 01:31:07 +00:00

56 lines
1.6 KiB
Go

// Copyright 2022 OpenSSF 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 gitlabrepo
import (
"fmt"
"github.com/xanzy/go-gitlab"
"github.com/ossf/scorecard/v4/clients"
)
type statusesHandler struct {
glClient *gitlab.Client
repourl *repoURL
}
func (handler *statusesHandler) init(repourl *repoURL) {
handler.repourl = repourl
}
// for gitlab this only works if ref is SHA.
func (handler *statusesHandler) listStatuses(ref string) ([]clients.Status, error) {
commitStatuses, _, err := handler.glClient.Commits.GetCommitStatuses(
handler.repourl.projectID, ref, &gitlab.GetCommitStatusesOptions{})
if err != nil {
return nil, fmt.Errorf("error getting commit statuses: %w", err)
}
return statusFromData(commitStatuses), nil
}
func statusFromData(commitStatuses []*gitlab.CommitStatus) []clients.Status {
var statuses []clients.Status
for _, commitStatus := range commitStatuses {
statuses = append(statuses, clients.Status{
State: commitStatus.Status,
Context: commitStatus.Name,
URL: commitStatus.TargetURL,
TargetURL: commitStatus.TargetURL,
})
}
return statuses
}