-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
64 lines (54 loc) · 1.52 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"context"
"delete-issues/config"
"github.com/machinebox/graphql"
"log"
"strconv"
"time"
)
func main() {
config.Load()
client := graphql.NewClient("https://api.github.com/graphql")
username := config.Get("username")
repo := config.Get("repo")
token := config.Get("token")
from, _ := strconv.ParseUint(config.Get("issueFrom"), 10, 32)
till, _ := strconv.ParseUint(config.Get("issueTill"), 10, 32)
for from < till+1 {
get_id_req := graphql.NewRequest(`
query ($username: String!, $repo: String!, $issueNumber: Int!) {
repository(owner: $username, name: $repo) {
issue(number: $issueNumber) {
id
}
}
}
`)
delete_issue_req := graphql.NewRequest(`
mutation($issueID: ID!) {
deleteIssue(input: { issueId: $issueID, clientMutationId: "auto-delete-spam-issues" }) {
repository {
id
}
}
}
`)
get_id_req.Var("username", username)
get_id_req.Var("repo", repo)
get_id_req.Var("issueNumber", from)
get_id_req.Header.Set("Authorization", "token "+token)
var issue_id_resp IssueIDResponse
if err := client.Run(context.Background(), get_id_req, &issue_id_resp); err != nil {
log.Fatal(err)
}
delete_issue_req.Var("issueID", issue_id_resp.Repository.Issue.Id)
delete_issue_req.Header.Set("Authorization", "token "+token)
if er := client.Run(context.Background(), delete_issue_req, nil); er != nil {
log.Fatal(er)
}
println("Deleted Issue #" + strconv.Itoa(int(from)))
from = from + 1
time.Sleep(1000 * time.Millisecond)
}
}