Last active
June 23, 2021 05:08
-
-
Save dpakach/22d7f4dc67ddd26c111487a18db4d03c to your computer and use it in GitHub Desktop.
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
package main | |
import ( | |
"regexp" | |
"fmt" | |
"strings" | |
"os" | |
"io" | |
"io/ioutil" | |
"net/http" | |
"encoding/json" | |
b64 "encoding/base64" | |
) | |
type issue struct { | |
State string `json:"state"` | |
} | |
var token = os.Getenv("GITHUB_TOKEN") | |
var githubUser = os.Getenv("GITHUB_USER") | |
var issueChecked = []string{} | |
func isInChecked(issue string) bool { | |
for _, item := range issueChecked { | |
if item == issue { | |
return true | |
} | |
} | |
return false | |
} | |
func main() { | |
if (token == "" || githubUser == "") { | |
panic("not github user or token") | |
} | |
r := regexp.MustCompile("(http|https):\\/\\/github.com\\/[a-zA-Z]+\\/[a-zA-Z]+\\/issues\\/\\d+") | |
dat, err := ioutil.ReadFile("ocis/tests/acceptance/expected-failures-API-on-OCIS-storage.md") | |
if err != nil { | |
panic(err) | |
} | |
auth := "Basic " + b64.StdEncoding.EncodeToString([]byte(githubUser + ":" + token)) | |
client := &http.Client{} | |
matches := r.FindAllString(string(dat), -1) | |
for _, url := range matches { | |
splits := strings.Split(url, "/") | |
issueID := strings.Join(splits[len(splits) - 4:], "/") | |
if (isInChecked(issueID)) { | |
continue | |
} | |
reqUrl := "https://api.github.com/repos/" + issueID | |
// fmt.Println(reqUrl, auth) | |
req, _ := http.NewRequest("GET", reqUrl, nil) | |
req.Header.Set("Authorization", auth) | |
resp, err := client.Do(req) | |
if err != nil { | |
fmt.Println("Error for requesting " + issueID) | |
} | |
body, err := io.ReadAll(resp.Body) | |
if err != nil { | |
panic(err) | |
} | |
if (resp.StatusCode == 403) { | |
panic("unauthorized status 403") | |
} | |
resp.Body.Close() | |
i := &issue{} | |
err = json.Unmarshal(body, i) | |
if err != nil { | |
panic (err) | |
} | |
if (i.State == "") { | |
fmt.Println("failed to get issue info for: " + issueID + " " + fmt.Sprint(resp.StatusCode)) | |
} | |
if (i.State == "closed") { | |
fmt.Println("\n\n====================") | |
fmt.Println("Closed Issue found: " + issueID) | |
fmt.Println("====================") | |
} | |
issueChecked = append(issueChecked, issueID) | |
} | |
fmt.Printf("Completed: checked %v issues", len(issueChecked)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment