run stale repo check as test instead (#4265)

This commit is contained in:
Amir Ariffin 2022-06-10 20:28:34 +08:00 committed by GitHub
parent 462dbbb9e7
commit 1fd356d91f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 9 deletions

View File

@ -13,6 +13,6 @@ jobs:
- name: Get dependencies - name: Get dependencies
run: go get -v -t -d ./... run: go get -v -t -d ./...
- name: run script - name: run script
run: go run test_stale_repositories.go scripts.go run: go test stale_repositories_test.go scripts.go
env: env:
OAUTH_TOKEN: ${{secrets.OAUTH_TOKEN}} OAUTH_TOKEN: ${{secrets.OAUTH_TOKEN}}

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
tmpl/index.html tmpl/index.html
awesome-go awesome-go
vendor
# Folders # Folders
.idea .idea

View File

@ -2,6 +2,7 @@ package main
import ( import (
"bytes" "bytes"
"context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"log" "log"
@ -9,6 +10,7 @@ import (
"os" "os"
"regexp" "regexp"
"strings" "strings"
"testing"
"text/template" "text/template"
"time" "time"
@ -36,8 +38,6 @@ const movedPermanently = " status code 301 received"
const status302 = " status code 302 received" const status302 = " status code 302 received"
const archived = " repository has been archived" 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 //LIMIT specifies the max number of repositories that are added in a single run of the script
var LIMIT = 10 var LIMIT = 10
var ctr = 0 var ctr = 0
@ -140,10 +140,7 @@ func getAllFlaggedRepositories(client *http.Client, flaggedRepositories *map[str
} }
func containsOpenIssue(link string, openIssues map[string]bool) bool { func containsOpenIssue(link string, openIssues map[string]bool) bool {
_, ok := openIssues[link] _, ok := openIssues[link]
if ok { return ok
return true
}
return false
} }
func testRepoState(toRun bool, href string, client *http.Client, staleRepos *[]string) bool { func testRepoState(toRun bool, href string, client *http.Client, staleRepos *[]string) bool {
if toRun { if toRun {
@ -232,7 +229,7 @@ func testStaleRepository() {
tokenSource := &tokenSource{ tokenSource := &tokenSource{
AccessToken: oauth, AccessToken: oauth,
} }
client = oauth2.NewClient(oauth2.NoContext, tokenSource) client = oauth2.NewClient(context.Background(), tokenSource)
} }
err := getAllFlaggedRepositories(client, &addressedRepositories) err := getAllFlaggedRepositories(client, &addressedRepositories)
@ -270,6 +267,6 @@ func testStaleRepository() {
createIssue(staleRepos, client) createIssue(staleRepos, client)
} }
func main() { func TestStaleRepository(t *testing.T) {
testStaleRepository() testStaleRepository()
} }