@@ -694,6 +694,42 @@ func PrepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *git.C
694
694
return compareInfo
695
695
}
696
696
697
+ type pullCommitList struct {
698
+ Commits []pull_service.CommitInfo `json:"commits"`
699
+ LastReviewCommitSha string `json:"last_review_commit_sha"`
700
+ Locale map [string ]string `json:"locale"`
701
+ }
702
+
703
+ // GetPullCommits get all commits for given pull request
704
+ func GetPullCommits (ctx * context.Context ) {
705
+ issue := checkPullInfo (ctx )
706
+ if ctx .Written () {
707
+ return
708
+ }
709
+ resp := & pullCommitList {}
710
+
711
+ commits , lastReviewCommitSha , err := pull_service .GetPullCommits (ctx , issue )
712
+ if err != nil {
713
+ ctx .JSON (http .StatusInternalServerError , err )
714
+ return
715
+ }
716
+
717
+ // Get the needed locale
718
+ resp .Locale = map [string ]string {
719
+ "lang" : ctx .Locale .Language (),
720
+ "filter_changes_by_commit" : ctx .Tr ("repo.pulls.filter_changes_by_commit" ),
721
+ "show_all_commits" : ctx .Tr ("repo.pulls.show_all_commits" ),
722
+ "stats_num_commits" : ctx .TrN (len (commits ), "repo.activity.git_stats_commit_1" , "repo.activity.git_stats_commit_n" , len (commits )),
723
+ "show_changes_since_your_last_review" : ctx .Tr ("repo.pulls.show_changes_since_your_last_review" ),
724
+ "select_commit_hold_shift_for_range" : ctx .Tr ("repo.pulls.select_commit_hold_shift_for_range" ),
725
+ }
726
+
727
+ resp .Commits = commits
728
+ resp .LastReviewCommitSha = lastReviewCommitSha
729
+
730
+ ctx .JSON (http .StatusOK , resp )
731
+ }
732
+
697
733
// ViewPullCommits show commits for a pull request
698
734
func ViewPullCommits (ctx * context.Context ) {
699
735
ctx .Data ["PageIsPullList" ] = true
@@ -739,7 +775,7 @@ func ViewPullCommits(ctx *context.Context) {
739
775
}
740
776
741
777
// ViewPullFiles render pull request changed files list page
742
- func ViewPullFiles (ctx * context.Context ) {
778
+ func viewPullFiles (ctx * context.Context , specifiedStartCommit , specifiedEndCommit string , willShowSpecifiedCommitRange , willShowSpecifiedCommit bool ) {
743
779
ctx .Data ["PageIsPullList" ] = true
744
780
ctx .Data ["PageIsPullFiles" ] = true
745
781
@@ -762,6 +798,33 @@ func ViewPullFiles(ctx *context.Context) {
762
798
prInfo = PrepareViewPullInfo (ctx , issue )
763
799
}
764
800
801
+ // Validate the given commit sha to show (if any passed)
802
+ if willShowSpecifiedCommit || willShowSpecifiedCommitRange {
803
+
804
+ foundStartCommit := len (specifiedStartCommit ) == 0
805
+ foundEndCommit := len (specifiedEndCommit ) == 0
806
+
807
+ if ! (foundStartCommit && foundEndCommit ) {
808
+ for _ , commit := range prInfo .Commits {
809
+ if commit .ID .String () == specifiedStartCommit {
810
+ foundStartCommit = true
811
+ }
812
+ if commit .ID .String () == specifiedEndCommit {
813
+ foundEndCommit = true
814
+ }
815
+
816
+ if foundStartCommit && foundEndCommit {
817
+ break
818
+ }
819
+ }
820
+ }
821
+
822
+ if ! (foundStartCommit && foundEndCommit ) {
823
+ ctx .NotFound ("Given SHA1 not found for this PR" , nil )
824
+ return
825
+ }
826
+ }
827
+
765
828
if ctx .Written () {
766
829
return
767
830
} else if prInfo == nil {
@@ -775,12 +838,30 @@ func ViewPullFiles(ctx *context.Context) {
775
838
return
776
839
}
777
840
778
- startCommitID = prInfo .MergeBase
779
- endCommitID = headCommitID
841
+ ctx .Data ["IsShowingOnlySingleCommit" ] = willShowSpecifiedCommit
842
+
843
+ if willShowSpecifiedCommit || willShowSpecifiedCommitRange {
844
+ if len (specifiedEndCommit ) > 0 {
845
+ endCommitID = specifiedEndCommit
846
+ } else {
847
+ endCommitID = headCommitID
848
+ }
849
+ if len (specifiedStartCommit ) > 0 {
850
+ startCommitID = specifiedStartCommit
851
+ } else {
852
+ startCommitID = prInfo .MergeBase
853
+ }
854
+ ctx .Data ["IsShowingAllCommits" ] = false
855
+ } else {
856
+ endCommitID = headCommitID
857
+ startCommitID = prInfo .MergeBase
858
+ ctx .Data ["IsShowingAllCommits" ] = true
859
+ }
780
860
781
861
ctx .Data ["Username" ] = ctx .Repo .Owner .Name
782
862
ctx .Data ["Reponame" ] = ctx .Repo .Repository .Name
783
863
ctx .Data ["AfterCommitID" ] = endCommitID
864
+ ctx .Data ["BeforeCommitID" ] = startCommitID
784
865
785
866
fileOnly := ctx .FormBool ("file-only" )
786
867
@@ -789,8 +870,8 @@ func ViewPullFiles(ctx *context.Context) {
789
870
if fileOnly && (len (files ) == 2 || len (files ) == 1 ) {
790
871
maxLines , maxFiles = - 1 , - 1
791
872
}
873
+
792
874
diffOptions := & gitdiff.DiffOptions {
793
- BeforeCommitID : startCommitID ,
794
875
AfterCommitID : endCommitID ,
795
876
SkipTo : ctx .FormString ("skip-to" ),
796
877
MaxLines : maxLines ,
@@ -799,9 +880,18 @@ func ViewPullFiles(ctx *context.Context) {
799
880
WhitespaceBehavior : gitdiff .GetWhitespaceFlag (ctx .Data ["WhitespaceBehavior" ].(string )),
800
881
}
801
882
883
+ if ! willShowSpecifiedCommit {
884
+ diffOptions .BeforeCommitID = startCommitID
885
+ }
886
+
802
887
var methodWithError string
803
888
var diff * gitdiff.Diff
804
- if ! ctx .IsSigned {
889
+
890
+ // if we're not logged in or only a single commit (or commit range) is shown we
891
+ // have to load only the diff and not get the viewed information
892
+ // as the viewed information is designed to be loaded only on latest PR
893
+ // diff and if you're signed in.
894
+ if ! ctx .IsSigned || willShowSpecifiedCommit || willShowSpecifiedCommitRange {
805
895
diff , err = gitdiff .GetDiff (gitRepo , diffOptions , files ... )
806
896
methodWithError = "GetDiff"
807
897
} else {
@@ -908,6 +998,22 @@ func ViewPullFiles(ctx *context.Context) {
908
998
ctx .HTML (http .StatusOK , tplPullFiles )
909
999
}
910
1000
1001
+ func ViewPullFilesForSingleCommit (ctx * context.Context ) {
1002
+ viewPullFiles (ctx , "" , ctx .Params ("sha" ), true , true )
1003
+ }
1004
+
1005
+ func ViewPullFilesForRange (ctx * context.Context ) {
1006
+ viewPullFiles (ctx , ctx .Params ("shaFrom" ), ctx .Params ("shaTo" ), true , false )
1007
+ }
1008
+
1009
+ func ViewPullFilesStartingFromCommit (ctx * context.Context ) {
1010
+ viewPullFiles (ctx , "" , ctx .Params ("sha" ), true , false )
1011
+ }
1012
+
1013
+ func ViewPullFilesForAllCommitsOfPr (ctx * context.Context ) {
1014
+ viewPullFiles (ctx , "" , "" , false , false )
1015
+ }
1016
+
911
1017
// UpdatePullRequest merge PR's baseBranch into headBranch
912
1018
func UpdatePullRequest (ctx * context.Context ) {
913
1019
issue := checkPullInfo (ctx )
0 commit comments