コード例 #1
0
ファイル: diff.go プロジェクト: git-comment/git-comment
// 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)
		})
	})
}
コード例 #2
0
ファイル: lookup.go プロジェクト: git-comment/git-comment
// 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())
		})
	})
}
コード例 #3
0
ファイル: storage.go プロジェクト: git-comment/git-comment
// 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)
		})
	})
}
コード例 #4
0
ファイル: lookup.go プロジェクト: git-comment/git-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))
		})
	})
}
コード例 #5
0
ファイル: storage.go プロジェクト: git-comment/git-comment
// 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)
			})
		})
	})
}
コード例 #6
0
ファイル: remote.go プロジェクト: git-comment/git-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))
		})
	})
}
コード例 #7
0
ファイル: version.go プロジェクト: git-comment/git-comment
// 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)
		})
	})
}
コード例 #8
0
ファイル: search.go プロジェクト: git-comment/git-comment
// 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)
		})
	})
}
コード例 #9
0
ファイル: storage.go プロジェクト: git-comment/git-comment
// 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)
				})
			})
		})
	})
}