Exemple #1
0
func (gp GerritProject) Client() *gerrit.Client {
	cookieFile := filepath.Join(homeDir(), "keys", "gerrit-letsusegerrit.cookies")
	if _, err := os.Stat(cookieFile); err != nil {
		log.Fatalf("Can't stat cookie file for Gerrit: %v", cookieFile)
	}
	return gerrit.NewClient("https://"+gp.Instance+"-review.googlesource.com", gerrit.GitCookieFileAuth(cookieFile))
}
Exemple #2
0
func (gc gerritChange) IsStale() (bool, error) {
	c := gerrit.NewClient("https://"+gc.Server, gerrit.NoAuth)
	ci, err := c.GetChangeDetail(gc.ID)
	if err != nil {
		return false, err
	}
	switch ci.Status {
	case "SUBMITTED", "MERGED", "ABANDONED":
		return true, nil
	}
	return false, nil
}
Exemple #3
0
func checkTryBuildDeps() error {
	if !hasStorageScope() {
		return errors.New("coordinator's GCE instance lacks the storage service scope")
	}
	wr := storage.NewWriter(serviceCtx, buildLogBucket(), "hello.txt")
	fmt.Fprintf(wr, "Hello, world! Coordinator start-up at %v", time.Now())
	if err := wr.Close(); err != nil {
		return fmt.Errorf("test write of a GCS object to bucket %q failed: %v", buildLogBucket(), err)
	}
	gobotPass, err := metadata.ProjectAttributeValue("gobot-password")
	if err != nil {
		return fmt.Errorf("failed to get project metadata 'gobot-password': %v", err)
	}
	gerritClient = gerrit.NewClient("https://go-review.googlesource.com",
		gerrit.BasicAuth("git-gobot.golang.org", strings.TrimSpace(string(gobotPass))))

	return nil
}
Exemple #4
0
func main() {
	gobotPass, err := ioutil.ReadFile(filepath.Join(os.Getenv("HOME"), "keys", "gobot-golang-org.cookie"))
	if err != nil {
		log.Fatal(err)
	}
	c := gerrit.NewClient("https://go-review.googlesource.com",
		gerrit.BasicAuth("git-gobot.golang.org", strings.TrimSpace(string(gobotPass))))
	cl, err := c.QueryChanges("label:Run-TryBot=1 label:TryBot-Result=0 project:go status:open", gerrit.QueryChangesOpt{
		Fields: []string{"CURRENT_REVISION"},
	})
	if err != nil {
		log.Fatal(err)
	}
	v, _ := json.MarshalIndent(cl, "", "  ")
	os.Stdout.Write(v)

	log.Printf("SetReview = %v", c.SetReview("I2383397c056a9ffe174ac7c2c6e5bb334406fbf9", "current", gerrit.ReviewInput{
		Message: "test test",
		Labels: map[string]int{
			"TryBot-Result": 0,
		},
	}))
}
Exemple #5
0
func main() {
	log.SetFlags(0)
	log.SetPrefix("cl: ")
	flag.Usage = usage
	flag.Parse()

	switch *flagSort {
	case "", "age", "delay":
		// ok
	default:
		log.Fatal("unknown sort order")
	}

	c := gerrit.NewClient("https://go-review.googlesource.com", gerrit.NoAuth)
	query := strings.Join(flag.Args(), " ")
	cis, err := c.QueryChanges("is:open -project:scratch -message:do-not-review "+query, gerrit.QueryChangesOpt{
		N: 5000,
		Fields: []string{
			"LABELS",
			"CURRENT_FILES",
			"CURRENT_REVISION",
			"CURRENT_COMMIT",
			"MESSAGES",
			"DETAILED_ACCOUNTS", // fill out Owner.AuthorInfo, etc
			"DETAILED_LABELS",
		},
	})
	if err != nil {
		log.Fatalf("error querying changes: %v", err)
	}

	cls := []*CL{} // non-nil for json
	for _, ci := range cis {
		cl := parseCL(ci)
		if *flagNeedsReview && !cl.NeedsReview || !*flagClosed && cl.Closed {
			continue
		}
		cls = append(cls, cl)
	}

	switch *flagSort {
	case "":
		sort.Sort(byRepoAndSubject(cls))
	case "age":
		sort.Sort(byAge(cls))
	case "delay":
		sort.Sort(byDelay(cls))
	}

	if *flagJSON {
		data, err := json.MarshalIndent(cls, "", "\t")
		if err != nil {
			log.Fatal(err)
		}
		data = append(data, '\n')
		os.Stdout.Write(data)
		return
	}

	clPrefix := "CL "
	if *flagURL {
		clPrefix = "https://golang.org/cl/"
	}

	var projectLen, authorLen, reviewerLen int
	for _, cl := range cls {
		projectLen = max(projectLen, len(cl.Project))
		authorLen = max(authorLen, len(cl.Author))
		reviewerLen = max(reviewerLen, len(cl.Reviewer))
	}
	if authorLen > 12 {
		authorLen = 12
	}
	if reviewerLen > 12 {
		reviewerLen = 12
	}
	authorLen += 1   // for *
	reviewerLen += 3 // for +2*

	var buf bytes.Buffer
	for _, cl := range cls {
		fmt.Fprintf(&buf, "%s%-5d %3.0f/%3.0fd %-*s  %-*s %-*s %s%s\n",
			clPrefix, cl.Number,
			cl.Delay().Seconds()/86400, cl.Age().Seconds()/86400,
			projectLen, cl.Project,
			authorLen, authorString(cl, authorLen),
			reviewerLen, reviewerString(cl, reviewerLen),
			cl.Subject, issuesString(cl))
	}
	os.Stdout.Write(buf.Bytes())
}
Exemple #6
0
func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage: %s [flags] [CLs...]\n", os.Args[0])
		flag.PrintDefaults()
	}
	flag.Parse()

	queryParts := []string{}
	if *flagOutgoing {
		queryParts = append(queryParts, "is:open owner:self")
	}
	if *flagIncoming {
		queryParts = append(queryParts, "is:open reviewer:self -owner:self")
	}
	if *flagQuery != "" {
		queryParts = append(queryParts, *flagQuery)
	}
	for _, arg := range flag.Args() {
		if !clRe.MatchString(arg) {
			fmt.Fprintf(os.Stderr, "CL must be a CL number or Change-Id")
			os.Exit(2)
		}
		queryParts = append(queryParts, "change:"+arg)
	}
	if len(queryParts) == 0 {
		fmt.Fprintf(os.Stderr, "must specify something to fetch\n")
		os.Exit(2)
	}
	query := "(" + strings.Join(queryParts, ") OR (") + ")"

	if *flagVerbose {
		log.Printf("query: %s", query)
	}

	// Get the origin so we don't pull CLs for other repositories
	// in to this one.
	origin := gitOutput("config", "remote.origin.url")

	// Get the existing CL tags.
	haveTags := map[string]bool{}
	for _, tag := range strings.Split(gitOutput("tag"), "\n") {
		haveTags[tag] = true
	}

	c := gerrit.NewClient("https://go-review.googlesource.com", gerrit.GitCookiesAuth())

	cls, err := c.QueryChanges(query, gerrit.QueryChangesOpt{
		Fields: []string{"CURRENT_REVISION", "CURRENT_COMMIT"},
	})
	if err != nil {
		log.Fatal(err)
	}

	if *flagVerbose {
		v, _ := json.MarshalIndent(cls, "", "  ")
		log.Printf("Query response:\n%s\n", v)
	}

	// Collect git fetch and tag commands.
	fetchCmd := []string{"fetch", "--", origin}
	tags := make(map[string]*Tag)
	hashOrder := []string{}
	for _, cl := range cls {
		for commitID, rev := range cl.Revisions {
			tag := fmt.Sprintf("cl/%d/%d", cl.ChangeNumber, rev.PatchSetNumber)
			if !haveTags[tag] {
				any := false
				for _, fetch := range rev.Fetch {
					if fetch.URL == origin {
						fetchCmd = append(fetchCmd, fetch.Ref)
						any = true
						break
					}
				}
				if !any {
					continue
				}
			}

			tags[commitID] = &Tag{
				tag:    tag,
				commit: rev.Commit,
			}

			hashOrder = append(hashOrder, commitID)
		}
	}

	// Execute git fetch and tag commands.
	if len(fetchCmd) != 3 {
		git(fetchCmd...)
		fmt.Println()
	}
	for commitID, tag := range tags {
		if !haveTags[tag.tag] {
			git("tag", tag.tag, commitID)
		}
	}
	if *flagDry {
		// Separate command from printed tags.
		fmt.Println()
	}

	// Print tags.
	leafs := make(map[string]bool)
	for commitID, _ := range tags {
		leafs[commitID] = true
	}
	for _, tag := range tags {
		for _, parent := range tag.commit.Parents {
			leafs[parent.CommitID] = false
		}
	}

	printed := make(map[string]bool)
	needBlank := false
	for i := range hashOrder {
		commitID := hashOrder[len(hashOrder)-i-1]
		if !leafs[commitID] {
			continue
		}
		if needBlank {
			fmt.Println()
		}
		needBlank = printChain(tags, commitID, printed)
	}
}
Exemple #7
0
//Init function
func (g *GerritManager) Init(p *Project) {
	g.gerritClient = gerrit.NewClient(p.Configuration.ReviewAddress, nil)
	g.project = p.Name
}