// Find diffs on given commits // // If commitish resolves to a single commit, the diff is performed // between the commit and its parent. // @return result.Result<*Diff, error> func DiffCommits(repoPath, commitish string, contextLines uint32) result.Result { return gg.WithRepository(repoPath, func(repo *git.Repository) result.Result { commits := gg.ResolveCommits(repo, gg.ExpandCommitish(commitish)) return commits.FlatMap(func(commitRange interface{}) result.Result { return diffCommits(repo, commitRange.(*gg.CommitRange), contextLines) }) }) }
// Find comments in a commit range or on a single commit // @return result.Result<[]*Comment, error> func CommentsOnCommittish(repoPath string, committish string) result.Result { return gg.WithRepository(repoPath, func(repo *git.Repository) result.Result { resolution := gg.ResolveCommits(repo, committish) return resolution.FlatMap(func(commitRange interface{}) result.Result { return CommentsOnCommits(repo, commitRange.(*gg.CommitRange).Commits()) }) }) }
// Remove a comment from a commit // @return result.Result<*Comment, error> func DeleteComment(repoPath string, identifier string) result.Result { return gg.WithRepository(repoPath, func(repo *git.Repository) result.Result { return CommentByID(repo, identifier).FlatMap(func(c interface{}) result.Result { comment := c.(*Comment) comment.Deleted = true return writeCommentToDisk(repo, comment) }) }) }
// Finds all comments on a given commit // @return result.Result<[]*Comment, error> func CommentsOnCommit(repoPath string, commitHash string) result.Result { return gg.WithRepository(repoPath, func(repo *git.Repository) result.Result { hash := gg.ResolveSingleCommitHash(repo, commitHash) return hash.FlatMap(func(commit interface{}) result.Result { return gg.LookupCommit(repo, *(commit.(*string))) }).FlatMap(func(commit interface{}) result.Result { return commentsOnCommit(repo, commit.(*git.Commit)) }) }) }
// Update an existing comment with a new message // @return result.Result<*Comment, error> func UpdateComment(repoPath, identifier, committer, message string) result.Result { return gg.WithRepository(repoPath, func(repo *git.Repository) result.Result { return CommentByID(repo, identifier).FlatMap(func(c interface{}) result.Result { comment := c.(*Comment) return commentCommitter(repoPath, committer).FlatMap(func(committer interface{}) result.Result { comment.Amend(message, committer.(*Person)) return writeCommentToDisk(repo, comment) }) }) }) }
// 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)) }) }) }
// Check the version of git-comment in use against // the version in use in the repository. // @return result.Result<VersionStatus, error> func VersionCheck(repoPath, toolVersion string) result.Result { return gg.WithRepository(repoPath, func(repo *git.Repository) result.Result { return readVersion(repo).Analysis(func(version interface{}) result.Result { return compareVersion(toolVersion, version.(string)) }, func(err error) result.Result { if git.IsErrorCode(err, git.ErrNotFound) { return writeVersion(repo, toolVersion) } return result.NewFailure(err) }) }) }
// Open or create a search index // @return result.Result<bleve.Index, error> func openIndex(repoPath string, ifSuccess func(*git.Repository, bleve.Index) result.Result) result.Result { storage := filepath.Join(repoPath, gc.CommentStorageDir) indexPath := filepath.Join(storage, indexFilePath) return gg.WithRepository(repoPath, func(repo *git.Repository) result.Result { os.Mkdir(storage, 0700) success := func(index interface{}) result.Result { return ifSuccess(repo, index.(bleve.Index)) } return result.NewResult(bleve.Open(indexPath)).Analysis(success, func(err error) result.Result { mapping := bleve.NewIndexMapping() index := result.NewResult(bleve.New(indexPath, mapping)) return index.FlatMap(success) }) }) }
// Create a new comment on a commit, optionally with a file and line // @return result.Result<*string, error> func CreateComment(repoPath, commit, author, message string, fileRef *FileRef) result.Result { return gg.WithRepository(repoPath, func(repo *git.Repository) result.Result { return validatedCommitForComment(repo, commit).FlatMap(func(hash interface{}) result.Result { return commentAuthor(repoPath, author).FlatMap(func(author interface{}) result.Result { return NewComment(message, *(hash).(*string), fileRef, author.(*Person)) }).FlatMap(func(value interface{}) result.Result { comment := value.(*Comment) success := writeCommentToDisk(repo, comment) return success.FlatMap(func(value interface{}) result.Result { return result.NewSuccess(comment.ID) }) }) }) }) }