From 00a864e693434bce687f3f5145d8369583197b78 Mon Sep 17 00:00:00 2001 From: Christopher Brickley Date: Tue, 26 Aug 2014 08:20:18 -0400 Subject: add commit compare functionality --- models/action.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'models/action.go') diff --git a/models/action.go b/models/action.go index d536c84d..5a8c3169 100644 --- a/models/action.go +++ b/models/action.go @@ -172,7 +172,7 @@ func updateIssuesCommit(userId, repoId int64, repoUserName, repoName string, com // CommitRepoAction adds new action for committing repository. func CommitRepoAction(userId, repoUserId int64, userName, actEmail string, - repoId int64, repoUserName, repoName string, refFullName string, commit *base.PushCommits) error { + repoId int64, repoUserName, repoName string, refFullName string, commit *base.PushCommits, oldCommitId string, newCommitId string) error { opType := COMMIT_REPO // Check it's tag push or branch. @@ -226,6 +226,7 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string, } repoLink := fmt.Sprintf("%s%s/%s", setting.AppUrl, repoUserName, repoName) + compareUrl := fmt.Sprintf("%s/compare/%s...%s", repoLink, oldCommitId, newCommitId) commits := make([]*PayloadCommit, len(commit.Commits)) for i, cmt := range commit.Commits { commits[i] = &PayloadCommit{ @@ -258,6 +259,9 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string, Name: repo.Owner.LowerName, Email: repo.Owner.Email, }, + Before: oldCommitId, + After: newCommitId, + CompareUrl: compareUrl, } for _, w := range ws { -- cgit v1.2.3 From af0741da07ec190804fff2a84c3813fc62a1c3ba Mon Sep 17 00:00:00 2001 From: Christopher Brickley Date: Mon, 1 Sep 2014 19:19:56 -0400 Subject: handle initial commit for compareUrl --- models/action.go | 6 +++++- models/slack.go | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'models/action.go') diff --git a/models/action.go b/models/action.go index 5a8c3169..f739fc35 100644 --- a/models/action.go +++ b/models/action.go @@ -226,7 +226,11 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string, } repoLink := fmt.Sprintf("%s%s/%s", setting.AppUrl, repoUserName, repoName) - compareUrl := fmt.Sprintf("%s/compare/%s...%s", repoLink, oldCommitId, newCommitId) + compareUrl := "" + // if not the first commit, set the compareUrl + if !strings.HasPrefix(oldCommitId, "0000000") { + compareUrl = fmt.Sprintf("%s/compare/%s...%s", repoLink, oldCommitId, newCommitId) + } commits := make([]*PayloadCommit, len(commit.Commits)) for i, cmt := range commit.Commits { commits[i] = &PayloadCommit{ diff --git a/models/slack.go b/models/slack.go index 714b2f6c..3dd40759 100644 --- a/models/slack.go +++ b/models/slack.go @@ -72,9 +72,14 @@ func getSlackPushPayload(p *Payload, slack *Slack) (*SlackPayload, error) { if len(p.Commits) == 1 { commitString = "1 new commit" + if p.CompareUrl != "" { + commitString = SlackLinkFormatter(p.CompareUrl, commitString) + } } else { commitString = fmt.Sprintf("%d new commits", len(p.Commits)) - commitString = SlackLinkFormatter(p.CompareUrl, commitString) + if p.CompareUrl != "" { + commitString = SlackLinkFormatter(p.CompareUrl, commitString) + } } repoLink := SlackLinkFormatter(p.Repo.Url, p.Repo.Name) -- cgit v1.2.3