diff --git a/.github/workflows/run-check.yaml b/.github/workflows/run-check.yaml index d17ad7a1..f9cfa9dc 100644 --- a/.github/workflows/run-check.yaml +++ b/.github/workflows/run-check.yaml @@ -13,6 +13,6 @@ jobs: - name: Get dependencies run: go get -v -t -d ./... - name: run script - run: go run test_stale_repositories.go scripts.go + run: go test stale_repositories_test.go scripts.go env: OAUTH_TOKEN: ${{secrets.OAUTH_TOKEN}} diff --git a/.gitignore b/.gitignore index 6230dcff..9a7c1cec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ tmpl/index.html awesome-go +vendor # Folders .idea diff --git a/test_stale_repositories.go b/stale_repositories_test.go similarity index 98% rename from test_stale_repositories.go rename to stale_repositories_test.go index 7fb65dea..8a992e4c 100644 --- a/test_stale_repositories.go +++ b/stale_repositories_test.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "context" "encoding/json" "fmt" "log" @@ -9,6 +10,7 @@ import ( "os" "regexp" "strings" + "testing" "text/template" "time" @@ -36,8 +38,6 @@ const movedPermanently = " status code 301 received" const status302 = " status code 302 received" const archived = " repository has been archived" -var delay time.Duration = 1 - //LIMIT specifies the max number of repositories that are added in a single run of the script var LIMIT = 10 var ctr = 0 @@ -140,10 +140,7 @@ func getAllFlaggedRepositories(client *http.Client, flaggedRepositories *map[str } func containsOpenIssue(link string, openIssues map[string]bool) bool { _, ok := openIssues[link] - if ok { - return true - } - return false + return ok } func testRepoState(toRun bool, href string, client *http.Client, staleRepos *[]string) bool { if toRun { @@ -232,7 +229,7 @@ func testStaleRepository() { tokenSource := &tokenSource{ AccessToken: oauth, } - client = oauth2.NewClient(oauth2.NoContext, tokenSource) + client = oauth2.NewClient(context.Background(), tokenSource) } err := getAllFlaggedRepositories(client, &addressedRepositories) @@ -270,6 +267,6 @@ func testStaleRepository() { createIssue(staleRepos, client) } -func main() { +func TestStaleRepository(t *testing.T) { testStaleRepository() }