示例#1
0
// LatestDeployed returns the latest commit deployed into the host.
func (c control) LatestDeployed(ctx context.Context, host config.Host, repoPath string) (rev, srcRev revision.Revision, err error) {
	hostname := host.URI
	cmd := fmt.Sprintf("git --git-dir=%s rev-parse HEAD", repoPath)
	buf, err := c.ssh.Output(ctx, hostname, cmd)
	if err != nil {
		glog.Errorf("Failed to get latest deployed commit from %s:%s : %v", host.URI, repoPath, err)
		return "", "", err
	}
	rev = revision.Revision(strings.TrimSpace(string(buf)))
	return rev, rev, nil
}
示例#2
0
// Latest returns the latest commit in the given reference.
func (c control) Latest(ctx context.Context, owner, repo, ref string) (rev, srcRev revision.Revision, err error) {
	opts := &github.CommitsListOptions{SHA: ref}
	commits, _, err := c.gcl.ListCommits(owner, repo, opts)
	if err != nil {
		glog.Errorf("Failed to get commits from GitHub: %v", err)
		return "", "", err
	}
	if len(commits) == 0 {
		glog.Errorf("No commits in branch %s of %s/%s", ref, owner, repo)
		return "", "", fmt.Errorf("no commits in the branch %s", ref)
	}
	rev = revision.Revision(*commits[0].SHA)
	return rev, rev, nil
}