Skip to content

Commit cc31a21

Browse files
authored
Merge pull request #781 from andreynering/notifications-step-5
Notifications step 5
2 parents 31c717f + aa59131 commit cc31a21

File tree

6 files changed

+49
-25
lines changed

6 files changed

+49
-25
lines changed

models/issue.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ func (issue *Issue) loadRepo(e Engine) (err error) {
9393
return nil
9494
}
9595

96+
// GetPullRequest returns the issue pull request
97+
func (issue *Issue) GetPullRequest() (pr *PullRequest, err error) {
98+
if !issue.IsPull {
99+
return nil, fmt.Errorf("Issue is not a pull request")
100+
}
101+
102+
pr, err = getPullRequestByIssueID(x, issue.ID)
103+
return
104+
}
105+
96106
func (issue *Issue) loadAttributes(e Engine) (err error) {
97107
if err := issue.loadRepo(e); err != nil {
98108
return err
@@ -953,9 +963,9 @@ func Issues(opts *IssuesOptions) ([]*Issue, error) {
953963

954964
switch opts.IsPull {
955965
case util.OptionalBoolTrue:
956-
sess.And("issue.is_pull=?",true)
966+
sess.And("issue.is_pull=?", true)
957967
case util.OptionalBoolFalse:
958-
sess.And("issue.is_pull=?",false)
968+
sess.And("issue.is_pull=?", false)
959969
}
960970

961971
sortIssuesSession(sess, opts.SortType)
@@ -1780,4 +1790,3 @@ func DeleteMilestoneByRepoID(repoID, id int64) error {
17801790
}
17811791
return sess.Commit()
17821792
}
1783-

public/css/index.css

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2726,17 +2726,16 @@ footer .ui.language .menu {
27262726
.user.notification table tr {
27272727
cursor: pointer;
27282728
}
2729-
.user.notification .octicon-issue-opened,
2730-
.user.notification .octicon-git-pull-request {
2729+
.user.notification .octicon.green {
27312730
color: #21ba45;
27322731
}
2733-
.user.notification .octicon-issue-closed {
2732+
.user.notification .octicon.red {
27342733
color: #d01919;
27352734
}
2736-
.user.notification .octicon-git-merge {
2735+
.user.notification .octicon.purple {
27372736
color: #a333c8;
27382737
}
2739-
.user.notification .octicon-pin {
2738+
.user.notification .octicon.blue {
27402739
color: #2185d0;
27412740
}
27422741
.dashboard {

public/less/_user.less

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,19 @@
9999
}
100100
}
101101

102-
.octicon-issue-opened, .octicon-git-pull-request {
103-
color: #21ba45;
104-
}
105-
.octicon-issue-closed {
106-
color: #d01919;
107-
}
108-
.octicon-git-merge {
109-
color: #a333c8;
110-
}
111-
.octicon-pin {
112-
color: #2185d0;
102+
.octicon {
103+
&.green {
104+
color: #21ba45;
105+
}
106+
&.red {
107+
color: #d01919;
108+
}
109+
&.purple {
110+
color: #a333c8;
111+
}
112+
&.blue {
113+
color: #2185d0;
114+
}
113115
}
114116
}
115117
}

routers/repo/issue.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,8 @@ func NewComment(ctx *context.Context, form auth.CreateCommentForm) {
875875
log.Error(4, "ChangeStatus: %v", err)
876876
} else {
877877
log.Trace("Issue [%d] status changed to closed: %v", issue.ID, issue.IsClosed)
878+
879+
notification.Service.NotifyIssue(issue, ctx.User.ID)
878880
}
879881
}
880882
}

routers/repo/pull.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ import (
1616
"code.gitea.io/gitea/modules/base"
1717
"code.gitea.io/gitea/modules/context"
1818
"code.gitea.io/gitea/modules/log"
19+
"code.gitea.io/gitea/modules/notification"
1920
"code.gitea.io/gitea/modules/setting"
21+
2022
"github.com/Unknwon/com"
2123
)
2224

@@ -415,6 +417,8 @@ func MergePullRequest(ctx *context.Context) {
415417
return
416418
}
417419

420+
notification.Service.NotifyIssue(pr.Issue, ctx.User.ID)
421+
418422
log.Trace("Pull request merged: %d", pr.ID)
419423
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
420424
}
@@ -707,6 +711,8 @@ func CompareAndPullRequestPost(ctx *context.Context, form auth.CreateIssueForm)
707711
return
708712
}
709713

714+
notification.Service.NotifyIssue(pullIssue, ctx.User.ID)
715+
710716
log.Trace("Pull request created: %d/%d", repo.ID, pullIssue.ID)
711717
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pullIssue.Index))
712718
}

templates/user/notification/notification.tmpl

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,31 @@
4040
<i class="blue octicon octicon-pin"></i>
4141
{{else if $issue.IsPull}}
4242
{{if $issue.IsClosed}}
43-
<i class="octicon octicon-git-merge"></i>
43+
{{if $issue.GetPullRequest.HasMerged}}
44+
<i class="purple octicon octicon-git-merge"></i>
45+
{{else}}
46+
<i class="red octicon octicon-git-pull-request"></i>
47+
{{end}}
4448
{{else}}
45-
<i class="octicon octicon-git-pull-request"></i>
49+
<i class="green octicon octicon-git-pull-request"></i>
4650
{{end}}
4751
{{else}}
4852
{{if $issue.IsClosed}}
49-
<i class="octicon octicon-issue-closed"></i>
53+
<i class="red octicon octicon-issue-closed"></i>
5054
{{else}}
51-
<i class="octicon octicon-issue-opened"></i>
55+
<i class="green octicon octicon-issue-opened"></i>
5256
{{end}}
5357
{{end}}
5458
</td>
55-
<td class="twelve wide">
59+
<td class="eleven wide">
5660
<a class="item" href="{{AppSubUrl}}/{{$repoOwner.Name}}/{{$repo.Name}}/issues/{{$issue.Index}}">
5761
#{{$issue.Index}} - {{$issue.Title}}
5862
</a>
5963
</td>
6064
<td>
61-
{{$repoOwner.Name}}/{{$repo.Name}}
65+
<a class="item" href="{{AppSubUrl}}/{{$repoOwner.Name}}/{{$repo.Name}}">
66+
{{$repoOwner.Name}}/{{$repo.Name}}
67+
</a>
6268
</td>
6369
<td class="collapsing">
6470
{{if ne $notification.Status 3}}

0 commit comments

Comments
 (0)