зеркало из https://github.com/golang/build.git
cmd/issuelock: new tool to freeze old Github issues
Updates golang/go#14903 Change-Id: I0d9a8482235ef7f94e2409eaa9b30ac161325711 Reviewed-on: https://go-review.googlesource.com/24504 Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Родитель
89e8d00eaf
Коммит
99b219b546
|
@ -0,0 +1,70 @@
|
|||
// Copyright 2016 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Command issuelock locks Github issues.
|
||||
package main
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/google/go-github/github"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
func main() {
|
||||
tokenFile := filepath.Join(os.Getenv("HOME"), "keys", "github-gobot")
|
||||
slurp, err := ioutil.ReadFile(tokenFile)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
f := strings.SplitN(strings.TrimSpace(string(slurp)), ":", 2)
|
||||
if len(f) != 2 || f[0] == "" || f[1] == "" {
|
||||
log.Fatalf("Expected token file %s to be of form <username>:<token>", tokenFile)
|
||||
}
|
||||
ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: f[1]})
|
||||
tc := oauth2.NewClient(oauth2.NoContext, ts)
|
||||
client := github.NewClient(tc)
|
||||
|
||||
tooOld := time.Now().Add(-365 * 24 * time.Hour).Format("2006-01-02")
|
||||
log.Printf("Freezing closed issues before %v", tooOld)
|
||||
for {
|
||||
result, response, err := client.Search.Issues("repo:golang/go is:closed -label:FrozenDueToAge updated:<="+tooOld, &github.SearchOptions{
|
||||
Sort: "created",
|
||||
Order: "asc",
|
||||
ListOptions: github.ListOptions{
|
||||
PerPage: 500,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if *result.Total == 0 {
|
||||
return
|
||||
}
|
||||
log.Printf("Matches: %d, Res: %#v", *result.Total, response)
|
||||
for _, is := range result.Issues {
|
||||
num := *is.Number
|
||||
log.Printf("Freezing issue: %d", *is.Number)
|
||||
if err := freeze(client, num); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
time.Sleep(500 * time.Millisecond) // be nice to github
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func freeze(client *github.Client, issueNum int) error {
|
||||
_, err := client.Issues.Lock("golang", "go", issueNum)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, _, err = client.Issues.AddLabelsToIssue("golang", "go", issueNum, []string{"FrozenDueToAge"})
|
||||
return err
|
||||
}
|
Загрузка…
Ссылка в новой задаче