当前位置: 首页>>代码示例>>Golang>>正文


Golang repository.Repo类代码示例

本文整理汇总了Golang中github.com/google/git-appraise/repository.Repo的典型用法代码示例。如果您正苦于以下问题:Golang Repo类的具体用法?Golang Repo怎么用?Golang Repo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Repo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: WriteNewReports

// WriteNewReports takes a list of CI reports read from GitHub, and writes to the repo any that are new.
//
// The passed in logChan variable is used as our intermediary for logging, and allows us to
// use the same logic for logging messages in either our CLI or our App Engine apps, even though
// the two have different logging frameworks.
func WriteNewReports(reportsMap map[string][]ci.Report, repo repository.Repo, logChan chan<- string) error {
	for commit, commitReports := range reportsMap {
		existingReports := ci.ParseAllValid(repo.GetNotes(ci.Ref, commit))
		for _, report := range commitReports {
			bytes, err := json.Marshal(report)
			note := repository.Note(bytes)
			if err != nil {
				return err
			}
			missing := true
			for _, existing := range existingReports {
				if existing == report {
					missing = false
				}
			}
			if missing {
				logChan <- fmt.Sprintf("Found a new report for %.12s: %q", commit, string(bytes))
				if err := repo.AppendNote(ci.Ref, commit, note); err != nil {
					return err
				}
			}
		}
	}
	return nil
}
开发者ID:google,项目名称:git-pull-request-mirror,代码行数:30,代码来源:output.go

示例2: updateReviewDiffs

// updateReviewDiffs updates the status of a differential review so that it matches the state of the repo.
//
// This consists of making sure the latest commit pushed to the review ref has a corresponding
// diff in the differential review.
func (arc Arcanist) updateReviewDiffs(repo repository.Repo, differentialReview DifferentialReview, headCommit string, req request.Request, r review.Review) {
	if differentialReview.isClosed() {
		return
	}

	headRevision := headCommit
	mergeBase, err := repo.MergeBase(req.TargetRef, headRevision)
	if err != nil {
		log.Fatal(err)
	}
	for _, hashPair := range differentialReview.Hashes {
		if len(hashPair) == 2 && hashPair[0] == commitHashType && hashPair[1] == headCommit {
			// The review already has the hash of the HEAD commit, so we have nothing to do beyond mirroring comments
			// and build status if applicable
			arc.mirrorCommentsIntoReview(repo, differentialReview, r)
			return
		}
	}

	diff, err := arc.createDifferentialDiff(repo, mergeBase, headRevision, req, differentialReview.Diffs)
	if err != nil {
		log.Fatal(err)
	}
	if diff == nil {
		// This means that phabricator silently refused to create the diff. Just move on.
		return
	}

	updateRequest := differentialUpdateRevisionRequest{ID: differentialReview.ID, DiffID: strconv.Itoa(diff.ID)}
	var updateResponse differentialUpdateRevisionResponse
	runArcCommandOrDie("differential.updaterevision", updateRequest, &updateResponse)
	if updateResponse.Error != "" {
		log.Fatal(updateResponse.ErrorMessage)
	}
}
开发者ID:google,项目名称:git-phabricator-mirror,代码行数:39,代码来源:arcanist.go

示例3: validateRebaseRequest

// Validate that the user's request to rebase a review makes sense.
//
// This checks both that the request is well formed, and that the
// corresponding review is in a state where rebasing is appropriate.
func validateRebaseRequest(repo repository.Repo, args []string) (*review.Review, error) {
	var r *review.Review
	var err error
	if len(args) > 1 {
		return nil, errors.New("Only rebasing a single review is supported.")
	}
	if len(args) == 1 {
		r, err = review.Get(repo, args[0])
	} else {
		r, err = review.GetCurrent(repo)
	}
	if err != nil {
		return nil, fmt.Errorf("Failed to load the review: %v\n", err)
	}
	if r == nil {
		return nil, errors.New("There is no matching review.")
	}

	if r.Submitted {
		return nil, errors.New("The review has already been submitted.")
	}

	target := r.Request.TargetRef
	if err := repo.VerifyGitRef(target); err != nil {
		return nil, err
	}

	return r, nil
}
开发者ID:google,项目名称:git-appraise,代码行数:33,代码来源:rebase.go

示例4: getDiffChanges

// getDiffChanges takes two revisions from which to generate a "git diff", and returns a
// slice of "changes" objects that represent that diff as parsed by Phabricator.
func (arc Arcanist) getDiffChanges(repo repository.Repo, from, to string) ([]interface{}, error) {
	// TODO(ojarjur): This is a big hack, but so far there does not seem to be a better solution:
	// We need to pass a list of "changes" JSON objects that contain the parsed diff contents.
	// The simplest way to do that parsing seems to be to create a rawDiff and have Phabricator
	// parse it on the server side. We then read back that diff, and return the changes from it.
	rawDiff, err := repo.Diff(from, to, "-M", "--no-ext-diff", "--no-textconv",
		"--src-prefix=a/", "--dst-prefix=b/",
		fmt.Sprintf("-U%d", 0x7fff), "--no-color")
	if err != nil {
		return nil, err
	}
	createRequest := differentialCreateRawDiffRequest{Diff: rawDiff}
	var createResponse differentialCreateRawDiffResponse
	runArcCommandOrDie("differential.createrawdiff", createRequest, &createResponse)
	if createResponse.Error != "" {
		return nil, fmt.Errorf(createResponse.ErrorMessage)
	}
	diffID := createResponse.Response.ID

	diff, err := readDiff(diffID)
	if err != nil {
		return nil, err
	}
	if diff != nil {
		return diff.Changes, nil
	}
	return nil, fmt.Errorf("Failed to retrieve the raw diff for %s..%s", from, to)
}
开发者ID:google,项目名称:git-phabricator-mirror,代码行数:30,代码来源:diff.go

示例5: GetFirstCommit

// GetFirstCommit returns the first commit that is included in the review
func (r DifferentialReview) GetFirstCommit(repo repository.Repo) string {
	var commits []string
	for _, hashPair := range r.Hashes {
		// We only care about the hashes for commits, which have exactly two
		// elements, the first of which is "gtcm".
		if len(hashPair) == 2 && hashPair[0] == commitHashType {
			commits = append(commits, hashPair[1])
		}
	}
	var commitTimestamps []int
	commitsByTimestamp := make(map[int]string)
	for _, commit := range commits {
		if _, err := repo.GetLastParent(commit); err == nil {
			timeString, err1 := repo.GetCommitTime(commit)
			timestamp, err2 := strconv.Atoi(timeString)
			if err1 == nil && err2 == nil {
				commitTimestamps = append(commitTimestamps, timestamp)
				// If there are multiple, equally old commits, then the last one wins.
				commitsByTimestamp[timestamp] = commit
			}
		}
	}
	if len(commitTimestamps) == 0 {
		return ""
	}
	sort.Ints(commitTimestamps)
	revision := commitsByTimestamp[commitTimestamps[0]]
	return revision
}
开发者ID:google,项目名称:git-phabricator-mirror,代码行数:30,代码来源:arcanist.go

示例6: WriteNewReviews

// WriteNewReviews takes a list of reviews read from GitHub, and writes to the repo any review
// data that has not already been written to it.
//
// The passed in logChan variable is used as our intermediary for logging, and allows us to
// use the same logic for logging messages in either our CLI or our App Engine apps, even though
// the two have different logging frameworks.
func WriteNewReviews(reviews []review.Review, repo repository.Repo, logChan chan<- string) error {
	existingReviews := review.ListAll(repo)
	for _, r := range reviews {
		requestNote, err := r.Request.Write()
		if err != nil {
			return err
		}
		if err != nil {
			return err
		}
		alreadyPresent := false
		if existing := findMatchingExistingReview(r, existingReviews); existing != nil {
			alreadyPresent = RequestsOverlap(existing.Request, r.Request)
			r.Revision = existing.Revision
		}
		if !alreadyPresent {
			requestJSON, err := r.GetJSON()
			if err != nil {
				return err
			}
			logChan <- fmt.Sprintf("Found a new review for %.12s:\n%s\n", r.Revision, requestJSON)
			if err := repo.AppendNote(request.Ref, r.Revision, requestNote); err != nil {
				return err
			}
		}
		if err := WriteNewComments(r, repo, logChan); err != nil {
			return err
		}
	}
	return nil
}
开发者ID:google,项目名称:git-pull-request-mirror,代码行数:37,代码来源:output.go

示例7: ListAll

// ListAll returns all reviews stored in the git-notes.
func ListAll(repo repository.Repo) []Summary {
	var reviews []Summary
	for _, revision := range repo.ListNotedRevisions(request.Ref) {
		review, err := GetSummary(repo, revision)
		if err == nil && review != nil {
			reviews = append(reviews, *review)
		}
	}
	return reviews
}
开发者ID:tml,项目名称:git-appraise,代码行数:11,代码来源:review.go

示例8: ListAll

// ListAll returns all reviews stored in the git-notes.
func ListAll(repo repository.Repo) []Review {
	var reviews []Review
	for _, revision := range repo.ListNotedRevisions(request.Ref) {
		review := Get(repo, revision)
		if review != nil {
			reviews = append(reviews, *review)
		}
	}
	return reviews
}
开发者ID:ojarjur,项目名称:git-appraise,代码行数:11,代码来源:review.go

示例9: commentOnReview

// commentOnReview adds a comment to the current code review.
func commentOnReview(repo repository.Repo, args []string) error {
	commentFlagSet.Parse(args)
	args = commentFlagSet.Args()
	if *commentLgtm && *commentNmw {
		return errors.New("You cannot combine the flags -lgtm and -nmw.")
	}
	if *commentLine != 0 && *commentFile == "" {
		return errors.New("Specifying a line number with the -l flag requires that you also specify a file name with the -f flag.")
	}

	var r *review.Review
	var err error
	if len(args) > 1 {
		return errors.New("Only accepting a single review is supported.")
	}

	if len(args) == 1 {
		r = review.Get(repo, args[0])
	} else {
		r, err = review.GetCurrent(repo)
	}

	if err != nil {
		return fmt.Errorf("Failed to load the review: %v\n", err)
	}
	if r == nil {
		return errors.New("There is no matching review.")
	}

	commentedUponCommit, err := r.GetHeadCommit()
	if err != nil {
		return err
	}
	location := comment.Location{
		Commit: commentedUponCommit,
	}
	if *commentFile != "" {
		location.Path = *commentFile
		if *commentLine != 0 {
			location.Range = &comment.Range{
				StartLine: uint32(*commentLine),
			}
		}
	}

	c := comment.New(repo.GetUserEmail(), *commentMessage)
	c.Location = &location
	c.Parent = *commentParent
	if *commentLgtm || *commentNmw {
		resolved := *commentLgtm
		c.Resolved = &resolved
	}
	return r.AddComment(c)
}
开发者ID:tweezy23,项目名称:git-appraise,代码行数:55,代码来源:comment.go

示例10: checkCommentLocation

// checkCommentLocation verifies that the given location exists at the given commit.
func checkCommentLocation(repo repository.Repo, commit, file string, line uint) error {
	contents, err := repo.Show(commit, file)
	if err != nil {
		return err
	}
	lines := strings.Split(contents, "\n")
	if line > uint(len(lines)) {
		return fmt.Errorf("Line number %d does not exist in file %q", line, file)
	}
	return nil
}
开发者ID:google,项目名称:git-appraise,代码行数:12,代码来源:comment.go

示例11: push

// push pushes the local git-notes used for reviews to a remote repo.
func push(repo repository.Repo, args []string) error {
	if len(args) > 1 {
		return errors.New("Only pushing to one remote at a time is supported.")
	}

	remote := "origin"
	if len(args) == 1 {
		remote = args[0]
	}

	return repo.PushNotes(remote, notesRefPattern)
}
开发者ID:pabranch,项目名称:git-appraise,代码行数:13,代码来源:push.go

示例12: rejectReview

// rejectReview adds an NMW comment to the current code review.
func rejectReview(repo repository.Repo, args []string) error {
	rejectFlagSet.Parse(args)
	args = rejectFlagSet.Args()

	var r *review.Review
	var err error
	if len(args) > 1 {
		return errors.New("Only rejecting a single review is supported.")
	}

	if len(args) == 1 {
		r, err = review.Get(repo, args[0])
	} else {
		r, err = review.GetCurrent(repo)
	}

	if err != nil {
		return fmt.Errorf("Failed to load the review: %v\n", err)
	}
	if r == nil {
		return errors.New("There is no matching review.")
	}

	if *rejectMessageFile != "" && *rejectMessage == "" {
		*rejectMessage, err = input.FromFile(*rejectMessageFile)
		if err != nil {
			return err
		}
	}
	if *rejectMessageFile == "" && *rejectMessage == "" {
		*rejectMessage, err = input.LaunchEditor(repo, commentFilename)
		if err != nil {
			return err
		}
	}

	rejectedCommit, err := r.GetHeadCommit()
	if err != nil {
		return err
	}
	location := comment.Location{
		Commit: rejectedCommit,
	}
	resolved := false
	userEmail, err := repo.GetUserEmail()
	if err != nil {
		return err
	}
	c := comment.New(userEmail, *rejectMessage)
	c.Location = &location
	c.Resolved = &resolved
	return r.AddComment(c)
}
开发者ID:google,项目名称:git-appraise,代码行数:54,代码来源:reject.go

示例13: Refresh

// Refresh advises the review tool that the code being reviewed has changed, and to reload it.
//
// This corresponds to calling the diffusion.looksoon API.
func (arc Arcanist) Refresh(repo repository.Repo) {
	// We cannot determine the repo's callsign (the identifier Phabricator uses for the repo)
	// in all cases, but we can figure it out in the case that the mirror runs on the same
	// directories that Phabricator is using. In that scenario, the repo directories default
	// to being named "/var/repo/<CALLSIGN>", so if the repo path starts with that prefix then
	// we can try to strip out that prefix and use the rest as a callsign.
	if strings.HasPrefix(repo.GetPath(), defaultRepoDirPrefix) {
		possibleCallsign := strings.TrimPrefix(repo.GetPath(), defaultRepoDirPrefix)
		request := lookSoonRequest{Callsigns: []string{possibleCallsign}}
		response := make(map[string]interface{})
		runArcCommandOrDie("diffusion.looksoon", request, &response)
	}
}
开发者ID:google,项目名称:git-phabricator-mirror,代码行数:16,代码来源:arcanist.go

示例14: syncNotes

func syncNotes(repo repository.Repo) error {
	var err error
	for attempt := 0; attempt < retryAttempts; attempt++ {
		err = repo.PullNotes(remoteName, notesRefPattern)
		if err == nil {
			err = repo.PushNotes(remoteName, notesRefPattern)
			if err == nil {
				return err
			}
		}
	}
	return err
}
开发者ID:google,项目名称:git-pull-request-mirror,代码行数:13,代码来源:ephemeral.go

示例15: pull

// pull updates the local git-notes used for reviews with those from a remote repo.
func pull(repo repository.Repo, args []string) error {
	if len(args) > 1 {
		return errors.New("Only pulling from one remote at a time is supported.")
	}

	remote := "origin"
	if len(args) == 1 {
		remote = args[0]
	}

	repo.PullNotes(remote, notesRefPattern)
	return nil
}
开发者ID:pabranch,项目名称:git-appraise,代码行数:14,代码来源:pull.go


注:本文中的github.com/google/git-appraise/repository.Repo类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。