Skip to content

Commit 94e7636

Browse files
committed
add compare api
1 parent 3afbbfe commit 94e7636

File tree

5 files changed

+798
-0
lines changed

5 files changed

+798
-0
lines changed

modules/structs/repo_compare.go

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright 2020 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package structs
6+
7+
// DiffLineSectionInfo represents diff line section meta data
8+
type DiffLineSectionInfo struct {
9+
Path string `json:"path"`
10+
LastLeftIdx int `json:"last_left_idx"`
11+
LastRightIdx int `json:"last_right_idx"`
12+
LeftIdx int `json:"left_idx"`
13+
RightIdx int `json:"right_idx"`
14+
LeftHunkSize int `json:"left_hunk_size"`
15+
RightHunkSize int `json:"right_hunk_size"`
16+
}
17+
18+
// DiffLine represents a line difference in a DiffSection.
19+
type DiffLine struct {
20+
LeftIdx int `json:"left_idx"`
21+
RightIdx int `json:"right_idx"`
22+
Type int `json:"type"`
23+
Content string `json:"content"`
24+
Comments []*Comment `json:"comments"`
25+
SectionInfo *DiffLineSectionInfo `json:"section_info"`
26+
}
27+
28+
// DiffSection represents a section of a DiffFile.
29+
type DiffSection struct {
30+
Name string `json:"name"`
31+
Lines []*DiffLine `json:"lines"`
32+
}
33+
34+
// DiffFile represents a file diff.
35+
type DiffFile struct {
36+
Name string `json:"name"`
37+
OldName string `json:"old_name"`
38+
Index int `json:"index"`
39+
Addition int `json:"addition"`
40+
Deletion int `json:"deletion"`
41+
Type int `json:"type"`
42+
IsCreated bool `json:"is_created"`
43+
IsDeleted bool `json:"is_deleted"`
44+
IsBin bool `json:"is_bin"`
45+
IsLFSFile bool `json:"is_lfs_file"`
46+
IsRenamed bool `json:"is_renamed"`
47+
IsSubmodule bool `json:"is_submoudule"`
48+
Sections []*DiffSection `json:"sections"`
49+
IsIncomplete bool `json:"is_incomplete"`
50+
}
51+
52+
// Diff represents a difference between two git trees.
53+
type Diff struct {
54+
TotalAddition int `json:"total_addition"`
55+
TotalDeletion int `json:"total_deletion"`
56+
Files []*DiffFile `json:"files"`
57+
IsIncomplete bool `json:"is_incomplete"`
58+
}
59+
60+
// Compare information.
61+
type Compare struct {
62+
Title string `json:"title"`
63+
Commits []*Commit `json:"commits"`
64+
CommitCount int `json:"commit_count"`
65+
Diff *Diff `json:"diff"`
66+
BaseCommitID string `json:"base_commit_id"`
67+
HeadCommitID string `json:"head_commit_id"`
68+
}

routers/api/v1/api.go

+1
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,7 @@ func RegisterRoutes(m *macaron.Macaron) {
782782
m.Get("/trees/:sha", context.RepoRef(), repo.GetTree)
783783
m.Get("/blobs/:sha", context.RepoRef(), repo.GetBlob)
784784
m.Get("/tags/:sha", context.RepoRef(), repo.GetTag)
785+
m.Get("/compare/*", context.ReferencesGitRepo(false), repo.GetCompare)
785786
}, reqRepoReader(models.UnitTypeCode))
786787
m.Group("/contents", func() {
787788
m.Get("", repo.GetContentsList)

0 commit comments

Comments
 (0)