Skip to content

Commit 411e822

Browse files
spencerschrockbalteravishay
authored andcommitted
🐛 Reset stored error when handler is re-inited or setup is re-run. (ossf#2893)
* Reset stored error when checkruns handler is re-inited or setup is run agaain. Signed-off-by: Spencer Schrock <[email protected]> * Add test. Signed-off-by: Spencer Schrock <[email protected]> --------- Signed-off-by: Spencer Schrock <[email protected]> Signed-off-by: Avishay <[email protected]>
1 parent 99aa24a commit 411e822

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

clients/githubrepo/checkruns.go

+2
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,12 @@ func (handler *checkrunsHandler) init(ctx context.Context, repourl *repoURL, com
8989
handler.checkData = new(checkRunsGraphqlData)
9090
handler.setupOnce = new(sync.Once)
9191
handler.checkRunsByRef = checkRunsByRef{}
92+
handler.errSetup = nil
9293
}
9394

9495
func (handler *checkrunsHandler) setup() error {
9596
handler.setupOnce.Do(func() {
97+
handler.errSetup = nil
9698
commitExpression := handler.repourl.commitExpression()
9799
vars := map[string]interface{}{
98100
"owner": githubv4.String(handler.repourl.owner),

clients/githubrepo/checkruns_test.go

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2023 OpenSSF Scorecard Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package githubrepo
16+
17+
import (
18+
"context"
19+
"testing"
20+
21+
sce "github.com/ossf/scorecard/v4/errors"
22+
)
23+
24+
func Test_init_clearsErr(t *testing.T) {
25+
handler := &checkrunsHandler{errSetup: sce.ErrScorecardInternal}
26+
handler.init(context.Background(), nil, 0)
27+
if handler.errSetup != nil {
28+
t.Errorf("expected nil error, got %v", handler.errSetup)
29+
}
30+
}

0 commit comments

Comments
 (0)