-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Raw results for Packaging check (#1913)
* update * update * update * update * update * update * update * updates * update * update * update * update * update * update * comments
- Loading branch information
1 parent
1d9cd05
commit 608da94
Showing
22 changed files
with
678 additions
and
232 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// 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 evaluation | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ossf/scorecard/v4/checker" | ||
sce "github.com/ossf/scorecard/v4/errors" | ||
) | ||
|
||
// Packaging applies the score policy for the Packaging check. | ||
func Packaging(name string, dl checker.DetailLogger, r *checker.PackagingData) checker.CheckResult { | ||
if r == nil { | ||
e := sce.WithMessage(sce.ErrScorecardInternal, "empty raw data") | ||
return checker.CreateRuntimeErrorResult(name, e) | ||
} | ||
|
||
pass := false | ||
for _, p := range r.Packages { | ||
if p.Msg != nil { | ||
// This is a debug message. Let's just replay the message. | ||
dl.Debug(&checker.LogMessage{ | ||
Text: *p.Msg, | ||
}) | ||
continue | ||
} | ||
|
||
// Presence of a single non-debug message means the | ||
// check passes. | ||
pass = true | ||
|
||
msg, err := createLogMessage(p) | ||
if err != nil { | ||
return checker.CreateRuntimeErrorResult(name, err) | ||
} | ||
dl.Info(&msg) | ||
} | ||
|
||
if pass { | ||
return checker.CreateMaxScoreResult(name, | ||
"publishing workflow detected") | ||
} | ||
|
||
dl.Warn(&checker.LogMessage{ | ||
Text: "no GitHub publishing workflow detected", | ||
}) | ||
|
||
return checker.CreateInconclusiveResult(name, | ||
"no published package detected") | ||
} | ||
|
||
func createLogMessage(p checker.Package) (checker.LogMessage, error) { | ||
var msg checker.LogMessage | ||
|
||
if p.Msg != nil { | ||
return msg, sce.WithMessage(sce.ErrScorecardInternal, "Msg should be nil") | ||
} | ||
|
||
if p.File == nil { | ||
return msg, sce.WithMessage(sce.ErrScorecardInternal, "File field is nil") | ||
} | ||
|
||
if p.File != nil { | ||
msg.Path = p.File.Path | ||
msg.Type = p.File.Type | ||
msg.Offset = p.File.Offset | ||
} | ||
|
||
if len(p.Runs) == 0 { | ||
return msg, sce.WithMessage(sce.ErrScorecardInternal, "no run data") | ||
} | ||
|
||
msg.Text = fmt.Sprintf("GitHub publishing workflow used in run %s", p.Runs[0].URL) | ||
|
||
return msg, nil | ||
} |
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
Oops, something went wrong.