Esempio n. 1
0
func diffRange(repo *git.Repository, commitRange *gg.CommitRange, contextLines uint32) result.Result {
	return result.Combine(func(values ...interface{}) result.Result {
		opts := values[2].(git.DiffOptions)
		opts.ContextLines = contextLines
		return result.NewResult(repo.DiffTreeToTree(
			values[0].(*git.Tree),
			values[1].(*git.Tree),
			&opts))
	}, commitTree(commitRange.Parent), commitTree(commitRange.Child), diffOptions())
}
Esempio n. 2
0
// @return result.Result<*Diff, error>
func diffCommits(repo *git.Repository, commitRange *gg.CommitRange, contextLines uint32) result.Result {
	comments := CommentsOnCommits(repo, commitRange.Commits())
	diff := diffRange(repo, commitRange, contextLines)
	return result.Combine(func(values ...interface{}) result.Result {
		parentID := commitRange.Parent.Id().String()
		childID := commitRange.Child.Id().String()
		files := parseDiffForLines(values[0].(*git.Diff), values[1].(CommentSlice))
		return result.NewSuccess(&Diff{files, parentID, childID})
	}, diff, comments)
}
Esempio n. 3
0
// @return result.Result<VersionStatus, error>
func compareVersion(toolVersion, repoVersion string) result.Result {
	errorMsg := fmt.Sprintf(toolInvalidError, toolVersion, repoVersion)
	invalidErr := result.NewFailure(errors.New(errorMsg))
	vt := result.NewResult(semver.Make(toolVersion)).RecoverWith(invalidErr)
	vr := result.NewResult(semver.Make(repoVersion)).RecoverWith(invalidErr)
	return result.Combine(func(values ...interface{}) result.Result {
		vt, vr := values[0].(semver.Version), values[1].(semver.Version)
		return comparisonStatus(vt.Compare(vr))
	}, vt, vr)
}
Esempio n. 4
0
// Configure a remote to fetch and push comment changes by default
// @return result.Result<bool, error>
func ConfigureRemoteForComments(repoPath, remoteName string) result.Result {
	return gg.WithRemote(repoPath, remoteName, func(remote *git.Remote) result.Result {
		success := func(values ...interface{}) result.Result {
			return result.NewSuccess(true)
		}
		return gg.WithRepository(repoPath, func(repo *git.Repository) result.Result {
			pushRef := commentDefaultPush
			fetchRef := fmt.Sprintf(commentDefaultFetch, remoteName)
			return result.Combine(success, gg.AddPush(repo, remote, pushRef), gg.AddFetch(repo, remote, fetchRef))
		})
	})
}
Esempio n. 5
0
// Finds all comments on an array of commits
// @return result.Result<[]*Comment, error>
func CommentsOnCommits(repo *git.Repository, commits []*git.Commit) result.Result {
	results := make([]result.Result, len(commits))
	for index, commit := range commits {
		results[index] = commentsOnCommit(repo, commit)
	}
	return result.Combine(func(values ...interface{}) result.Result {
		comments := make(CommentSlice, 0)
		for _, list := range values {
			for _, comment := range list.([]interface{}) {
				comments = append(comments, comment.(*Comment))
			}
		}
		sort.Stable(comments)
		return result.NewSuccess(comments)
	}, results...)
}
Esempio n. 6
0
// @return result.Result<bool, error>
func IndexComments(repoPath string) result.Result {
	return openIndex(repoPath, func(repo *git.Repository, index bleve.Index) result.Result {
		results := make([]result.Result, 0)
		batch := index.NewBatch()
		return gg.CommentRefIterator(repo, func(ref *git.Reference) {
			gc.CommentFromRef(repo, ref.Name()).FlatMap(func(c interface{}) result.Result {
				comment := c.(*gc.Comment)
				err := batch.Index(*comment.ID, commentIndex(comment))
				results = append(results, gg.BoolResult(true, err))
				return result.NewSuccess(true)
			})
		}).FlatMap(func(value interface{}) result.Result {
			return result.Combine(func(values ...interface{}) result.Result {
				return gg.BoolResult(true, index.Batch(batch))
			}, results...)
		})
	})
}