Skip to content

Commit 99feeef

Browse files
authored
Drop commit verify from tag hygiene (#212)
This drops the commit time verification from the tag hygiene check to be able to check it without requiring a commit. As the control status object now checks the commit time, we can drop the logic from the control reader. Signed-off-by: Adolfo García Veytia (Puerco) <[email protected]>
1 parent ee48799 commit 99feeef

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

sourcetool/pkg/ghcontrol/checklevel.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func enforcesTagHygiene(ruleset *github.RepositoryRuleset) bool {
131131
return false
132132
}
133133

134-
func (ghc *GitHubConnection) computeTagHygieneControl(ctx context.Context, _ string, allRulesets []*github.RepositoryRuleset, activityTime *time.Time) (*slsa.Control, error) {
134+
func (ghc *GitHubConnection) computeTagHygieneControl(ctx context.Context, allRulesets []*github.RepositoryRuleset) (*slsa.Control, error) {
135135
var validRuleset *github.RepositoryRuleset
136136
for _, ruleset := range allRulesets {
137137
if *ruleset.Target != github.RulesetTargetTag {
@@ -161,11 +161,6 @@ func (ghc *GitHubConnection) computeTagHygieneControl(ctx context.Context, _ str
161161
return nil, nil
162162
}
163163

164-
// Check that the commit was created after this rule was enabled.
165-
if activityTime.Before(validRuleset.UpdatedAt.Time) {
166-
return nil, nil
167-
}
168-
169164
return &slsa.Control{Name: slsa.TagHygiene, Since: validRuleset.UpdatedAt.Time}, nil
170165
}
171166

@@ -286,7 +281,7 @@ func (ghc *GitHubConnection) GetBranchControls(ctx context.Context, commit, ref
286281
if err != nil {
287282
return nil, err
288283
}
289-
TagHygieneControl, err := ghc.computeTagHygieneControl(ctx, commit, allRulesets, &activity.Timestamp)
284+
TagHygieneControl, err := ghc.computeTagHygieneControl(ctx, allRulesets)
290285
if err != nil {
291286
return nil, fmt.Errorf("could not populate TagHygieneControl: %w", err)
292287
}
@@ -303,13 +298,14 @@ func (ghc *GitHubConnection) GetTagControls(ctx context.Context, commit, ref str
303298

304299
allRulesets, _, err := ghc.Client().Repositories.GetAllRulesets(ctx, ghc.Owner(), ghc.Repo(), true)
305300
if err != nil {
306-
return nil, err
301+
return nil, fmt.Errorf("getting repository rules from API: %w", err)
307302
}
308-
TagHygieneControl, err := ghc.computeTagHygieneControl(ctx, commit, allRulesets, &controlStatus.CommitPushTime)
303+
304+
TagHygieneControl, err := ghc.computeTagHygieneControl(ctx, allRulesets)
309305
if err != nil {
310306
return nil, fmt.Errorf("could not populate TagHygieneControl: %w", err)
311307
}
312-
controlStatus.Controls.AddControl(TagHygieneControl)
308+
controlStatus.AddControl(TagHygieneControl)
313309

314310
return &controlStatus, nil
315311
}

0 commit comments

Comments
 (0)