Skip to content

Commit d474ae7

Browse files
Make issue tracker and wiki units separate structures in Repository API structure.
Signed-off-by: David Svantesson <[email protected]>
1 parent 5df6dca commit d474ae7

File tree

3 files changed

+138
-111
lines changed

3 files changed

+138
-111
lines changed

models/repo.go

Lines changed: 52 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -275,37 +275,35 @@ func (repo *Repository) innerAPIFormat(e Engine, mode AccessMode, isParent bool)
275275
}
276276
}
277277
hasIssues := false
278-
externalTracker := false
279-
externalTrackerURL := ""
280-
externalTrackerFormat := ""
281-
externalTrackerStyle := ""
282-
enableTimeTracker := false
283-
letOnlyContributorsTrackTime := false
284-
enableIssueDependencies := false
278+
var externalTracker *api.ExternalTracker
279+
var internalTracker *api.InternalTracker
285280
if unit, err := repo.getUnit(e, UnitTypeIssues); err == nil {
286281
config := unit.IssuesConfig()
287282
hasIssues = true
288-
enableTimeTracker = config.EnableTimetracker
289-
letOnlyContributorsTrackTime = config.AllowOnlyContributorsToTrackTime
290-
enableIssueDependencies = config.EnableDependencies
283+
internalTracker = &api.InternalTracker{
284+
EnableTimeTracker: config.EnableTimetracker,
285+
LetOnlyContributorsTrackTime: config.AllowOnlyContributorsToTrackTime,
286+
EnableIssueDependencies: config.EnableDependencies,
287+
}
291288
} else if unit, err := repo.getUnit(e, UnitTypeExternalTracker); err == nil {
292289
config := unit.ExternalTrackerConfig()
293290
hasIssues = true
294-
externalTracker = true
295-
externalTrackerURL = config.ExternalTrackerURL
296-
externalTrackerFormat = config.ExternalTrackerFormat
297-
externalTrackerStyle = config.ExternalTrackerStyle
291+
externalTracker = &api.ExternalTracker{
292+
ExternalTrackerURL: config.ExternalTrackerURL,
293+
ExternalTrackerFormat: config.ExternalTrackerFormat,
294+
ExternalTrackerStyle: config.ExternalTrackerStyle,
295+
}
298296
}
299297
hasWiki := false
300-
externalWiki := false
301-
externalWikiURL := ""
298+
var externalWiki *api.ExternalWiki
302299
if _, err := repo.getUnit(e, UnitTypeWiki); err == nil {
303300
hasWiki = true
304301
} else if unit, err := repo.getUnit(e, UnitTypeExternalWiki); err == nil {
305302
hasWiki = true
306303
config := unit.ExternalWikiConfig()
307-
externalWiki = true
308-
externalWikiURL = config.ExternalWikiURL
304+
externalWiki = &api.ExternalWiki{
305+
ExternalWikiURL: config.ExternalWikiURL,
306+
}
309307
}
310308
hasPullRequests := false
311309
ignoreWhitespaceConflicts := false
@@ -324,48 +322,42 @@ func (repo *Repository) innerAPIFormat(e Engine, mode AccessMode, isParent bool)
324322
}
325323

326324
return &api.Repository{
327-
ID: repo.ID,
328-
Owner: repo.Owner.APIFormat(),
329-
Name: repo.Name,
330-
FullName: repo.FullName(),
331-
Description: repo.Description,
332-
Private: repo.IsPrivate,
333-
Empty: repo.IsEmpty,
334-
Archived: repo.IsArchived,
335-
Size: int(repo.Size / 1024),
336-
Fork: repo.IsFork,
337-
Parent: parent,
338-
Mirror: repo.IsMirror,
339-
HTMLURL: repo.HTMLURL(),
340-
SSHURL: cloneLink.SSH,
341-
CloneURL: cloneLink.HTTPS,
342-
Website: repo.Website,
343-
Stars: repo.NumStars,
344-
Forks: repo.NumForks,
345-
Watchers: repo.NumWatches,
346-
OpenIssues: repo.NumOpenIssues,
347-
DefaultBranch: repo.DefaultBranch,
348-
Created: repo.CreatedUnix.AsTime(),
349-
Updated: repo.UpdatedUnix.AsTime(),
350-
Permissions: permission,
351-
HasIssues: hasIssues,
352-
ExternalTracker: externalTracker,
353-
ExternalTrackerURL: externalTrackerURL,
354-
ExternalTrackerFormat: externalTrackerFormat,
355-
ExternalTrackerStyle: externalTrackerStyle,
356-
EnableTimeTracker: enableTimeTracker,
357-
LetOnlyContributorsTrackTime: letOnlyContributorsTrackTime,
358-
EnableIssueDependencies: enableIssueDependencies,
359-
HasWiki: hasWiki,
360-
ExternalWiki: externalWiki,
361-
ExternalWikiURL: externalWikiURL,
362-
HasPullRequests: hasPullRequests,
363-
IgnoreWhitespaceConflicts: ignoreWhitespaceConflicts,
364-
AllowMerge: allowMerge,
365-
AllowRebase: allowRebase,
366-
AllowRebaseMerge: allowRebaseMerge,
367-
AllowSquash: allowSquash,
368-
AvatarURL: repo.avatarLink(e),
325+
ID: repo.ID,
326+
Owner: repo.Owner.APIFormat(),
327+
Name: repo.Name,
328+
FullName: repo.FullName(),
329+
Description: repo.Description,
330+
Private: repo.IsPrivate,
331+
Empty: repo.IsEmpty,
332+
Archived: repo.IsArchived,
333+
Size: int(repo.Size / 1024),
334+
Fork: repo.IsFork,
335+
Parent: parent,
336+
Mirror: repo.IsMirror,
337+
HTMLURL: repo.HTMLURL(),
338+
SSHURL: cloneLink.SSH,
339+
CloneURL: cloneLink.HTTPS,
340+
Website: repo.Website,
341+
Stars: repo.NumStars,
342+
Forks: repo.NumForks,
343+
Watchers: repo.NumWatches,
344+
OpenIssues: repo.NumOpenIssues,
345+
DefaultBranch: repo.DefaultBranch,
346+
Created: repo.CreatedUnix.AsTime(),
347+
Updated: repo.UpdatedUnix.AsTime(),
348+
Permissions: permission,
349+
HasIssues: hasIssues,
350+
ExternalTracker: externalTracker,
351+
InternalTracker: internalTracker,
352+
HasWiki: hasWiki,
353+
ExternalWiki: externalWiki,
354+
HasPullRequests: hasPullRequests,
355+
IgnoreWhitespaceConflicts: ignoreWhitespaceConflicts,
356+
AllowMerge: allowMerge,
357+
AllowRebase: allowRebase,
358+
AllowRebaseMerge: allowRebaseMerge,
359+
AllowSquash: allowSquash,
360+
AvatarURL: repo.avatarLink(e),
369361
}
370362
}
371363

modules/structs/repo.go

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,25 @@ type Permission struct {
1515
Pull bool `json:"pull"`
1616
}
1717

18+
// Represents settings for internal tracker
19+
type InternalTracker struct {
20+
EnableTimeTracker bool `json:"enable_time_tracker"`
21+
LetOnlyContributorsTrackTime bool `json:"let_only_contributors_track_time"`
22+
EnableIssueDependencies bool `json:"enable_issue_dependencies"`
23+
}
24+
25+
// Represents settings for external tracker
26+
type ExternalTracker struct {
27+
ExternalTrackerURL string `json:"external_tracker_url"`
28+
ExternalTrackerFormat string `json:"external_tracker_format"`
29+
ExternalTrackerStyle string `json:"external_tracker_style"`
30+
}
31+
32+
// Represents setting for external wiki
33+
type ExternalWiki struct {
34+
ExternalWikiURL string `json:"external_wiki_url"`
35+
}
36+
1837
// Repository represents a repository
1938
type Repository struct {
2039
ID int64 `json:"id"`
@@ -42,26 +61,20 @@ type Repository struct {
4261
// swagger:strfmt date-time
4362
Created time.Time `json:"created_at"`
4463
// swagger:strfmt date-time
45-
Updated time.Time `json:"updated_at"`
46-
Permissions *Permission `json:"permissions,omitempty"`
47-
HasIssues bool `json:"has_issues"`
48-
ExternalTracker bool `json:"external_tracker"`
49-
ExternalTrackerURL string `json:"external_tracker_url"`
50-
ExternalTrackerFormat string `json:"external_tracker_format"`
51-
ExternalTrackerStyle string `json:"external_tracker_style"`
52-
EnableTimeTracker bool `json:"enable_time_tracker"`
53-
LetOnlyContributorsTrackTime bool `json:"let_only_contributors_track_time"`
54-
EnableIssueDependencies bool `json:"enable_issue_dependencies"`
55-
HasWiki bool `json:"has_wiki"`
56-
ExternalWiki bool `json:"external_wiki"`
57-
ExternalWikiURL string `json:"external_wiki_url"`
58-
HasPullRequests bool `json:"has_pull_requests"`
59-
IgnoreWhitespaceConflicts bool `json:"ignore_whitespace_conflicts"`
60-
AllowMerge bool `json:"allow_merge_commits"`
61-
AllowRebase bool `json:"allow_rebase"`
62-
AllowRebaseMerge bool `json:"allow_rebase_explicit"`
63-
AllowSquash bool `json:"allow_squash_merge"`
64-
AvatarURL string `json:"avatar_url"`
64+
Updated time.Time `json:"updated_at"`
65+
Permissions *Permission `json:"permissions,omitempty"`
66+
HasIssues bool `json:"has_issues"`
67+
InternalTracker *InternalTracker `json:"internal_tracker,omitempty"`
68+
ExternalTracker *ExternalTracker `json:"external_tracker,omitempty"`
69+
HasWiki bool `json:"has_wiki"`
70+
ExternalWiki *ExternalWiki `json:"external_wiki,omitempty"`
71+
HasPullRequests bool `json:"has_pull_requests"`
72+
IgnoreWhitespaceConflicts bool `json:"ignore_whitespace_conflicts"`
73+
AllowMerge bool `json:"allow_merge_commits"`
74+
AllowRebase bool `json:"allow_rebase"`
75+
AllowRebaseMerge bool `json:"allow_rebase_explicit"`
76+
AllowSquash bool `json:"allow_squash_merge"`
77+
AvatarURL string `json:"avatar_url"`
6578
}
6679

6780
// CreateRepoOption options when creating repository

templates/swagger/v1_json.tmpl

Lines changed: 53 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8353,6 +8353,36 @@
83538353
},
83548354
"x-go-package": "code.gitea.io/gitea/modules/structs"
83558355
},
8356+
"ExternalTracker": {
8357+
"description": "Represents settings for external tracker",
8358+
"type": "object",
8359+
"properties": {
8360+
"external_tracker_format": {
8361+
"type": "string",
8362+
"x-go-name": "ExternalTrackerFormat"
8363+
},
8364+
"external_tracker_style": {
8365+
"type": "string",
8366+
"x-go-name": "ExternalTrackerStyle"
8367+
},
8368+
"external_tracker_url": {
8369+
"type": "string",
8370+
"x-go-name": "ExternalTrackerURL"
8371+
}
8372+
},
8373+
"x-go-package": "code.gitea.io/gitea/modules/structs"
8374+
},
8375+
"ExternalWiki": {
8376+
"description": "Represents setting for external wiki",
8377+
"type": "object",
8378+
"properties": {
8379+
"external_wiki_url": {
8380+
"type": "string",
8381+
"x-go-name": "ExternalWikiURL"
8382+
}
8383+
},
8384+
"x-go-package": "code.gitea.io/gitea/modules/structs"
8385+
},
83568386
"FileCommitResponse": {
83578387
"type": "object",
83588388
"title": "FileCommitResponse contains information generated from a Git commit for a repo's file.",
@@ -8717,6 +8747,25 @@
87178747
},
87188748
"x-go-package": "code.gitea.io/gitea/modules/structs"
87198749
},
8750+
"InternalTracker": {
8751+
"description": "Represents settings for internal tracker",
8752+
"type": "object",
8753+
"properties": {
8754+
"enable_issue_dependencies": {
8755+
"type": "boolean",
8756+
"x-go-name": "EnableIssueDependencies"
8757+
},
8758+
"enable_time_tracker": {
8759+
"type": "boolean",
8760+
"x-go-name": "EnableTimeTracker"
8761+
},
8762+
"let_only_contributors_track_time": {
8763+
"type": "boolean",
8764+
"x-go-name": "LetOnlyContributorsTrackTime"
8765+
}
8766+
},
8767+
"x-go-package": "code.gitea.io/gitea/modules/structs"
8768+
},
87208769
"Issue": {
87218770
"description": "Issue represents an issue in a repository",
87228771
"type": "object",
@@ -9553,37 +9602,11 @@
95539602
"type": "boolean",
95549603
"x-go-name": "Empty"
95559604
},
9556-
"enable_issue_dependencies": {
9557-
"type": "boolean",
9558-
"x-go-name": "EnableIssueDependencies"
9559-
},
9560-
"enable_time_tracker": {
9561-
"type": "boolean",
9562-
"x-go-name": "EnableTimeTracker"
9563-
},
95649605
"external_tracker": {
9565-
"type": "boolean",
9566-
"x-go-name": "ExternalTracker"
9567-
},
9568-
"external_tracker_format": {
9569-
"type": "string",
9570-
"x-go-name": "ExternalTrackerFormat"
9571-
},
9572-
"external_tracker_style": {
9573-
"type": "string",
9574-
"x-go-name": "ExternalTrackerStyle"
9575-
},
9576-
"external_tracker_url": {
9577-
"type": "string",
9578-
"x-go-name": "ExternalTrackerURL"
9606+
"$ref": "#/definitions/ExternalTracker"
95799607
},
95809608
"external_wiki": {
9581-
"type": "boolean",
9582-
"x-go-name": "ExternalWiki"
9583-
},
9584-
"external_wiki_url": {
9585-
"type": "string",
9586-
"x-go-name": "ExternalWikiURL"
9609+
"$ref": "#/definitions/ExternalWiki"
95879610
},
95889611
"fork": {
95899612
"type": "boolean",
@@ -9623,9 +9646,8 @@
96239646
"type": "boolean",
96249647
"x-go-name": "IgnoreWhitespaceConflicts"
96259648
},
9626-
"let_only_contributors_track_time": {
9627-
"type": "boolean",
9628-
"x-go-name": "LetOnlyContributorsTrackTime"
9649+
"internal_tracker": {
9650+
"$ref": "#/definitions/InternalTracker"
96299651
},
96309652
"mirror": {
96319653
"type": "boolean",

0 commit comments

Comments
 (0)