Skip to content

Commit e49ef56

Browse files
authored
Add allow_rebase_update, default_delete_branch_after_merge to repository api response (#20079)
`PATCH /repos/{owner}/{repo}` API allows users to update `allow_rebase_update`, `default_delete_branch_after_merge`, but `GET /repos/{owner}/{repo}` API does not return these two options, and API users has no other ways to find the state of these two options. This PR add `allow_rebase_update`, `default_delete_branch_after_merge` to repository query api response.
1 parent edd945b commit e49ef56

File tree

3 files changed

+82
-66
lines changed

3 files changed

+82
-66
lines changed

modules/convert/repository.go

Lines changed: 54 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ func innerToRepo(repo *repo_model.Repository, mode perm.AccessMode, isParent boo
7878
allowRebase := false
7979
allowRebaseMerge := false
8080
allowSquash := false
81+
allowRebaseUpdate := false
82+
defaultDeleteBranchAfterMerge := false
8183
defaultMergeStyle := repo_model.MergeStyleMerge
8284
if unit, err := repo.GetUnit(unit_model.TypePullRequests); err == nil {
8385
config := unit.PullRequestsConfig()
@@ -87,6 +89,8 @@ func innerToRepo(repo *repo_model.Repository, mode perm.AccessMode, isParent boo
8789
allowRebase = config.AllowRebase
8890
allowRebaseMerge = config.AllowRebaseMerge
8991
allowSquash = config.AllowSquash
92+
allowRebaseUpdate = config.AllowRebaseUpdate
93+
defaultDeleteBranchAfterMerge = config.DefaultDeleteBranchAfterMerge
9094
defaultMergeStyle = config.GetDefaultMergeStyle()
9195
}
9296
hasProjects := false
@@ -133,54 +137,56 @@ func innerToRepo(repo *repo_model.Repository, mode perm.AccessMode, isParent boo
133137
repoAPIURL := repo.APIURL()
134138

135139
return &api.Repository{
136-
ID: repo.ID,
137-
Owner: ToUserWithAccessMode(repo.Owner, mode),
138-
Name: repo.Name,
139-
FullName: repo.FullName(),
140-
Description: repo.Description,
141-
Private: repo.IsPrivate,
142-
Template: repo.IsTemplate,
143-
Empty: repo.IsEmpty,
144-
Archived: repo.IsArchived,
145-
Size: int(repo.Size / 1024),
146-
Fork: repo.IsFork,
147-
Parent: parent,
148-
Mirror: repo.IsMirror,
149-
HTMLURL: repo.HTMLURL(),
150-
SSHURL: cloneLink.SSH,
151-
CloneURL: cloneLink.HTTPS,
152-
OriginalURL: repo.SanitizedOriginalURL(),
153-
Website: repo.Website,
154-
Language: language,
155-
LanguagesURL: repoAPIURL + "/languages",
156-
Stars: repo.NumStars,
157-
Forks: repo.NumForks,
158-
Watchers: repo.NumWatches,
159-
OpenIssues: repo.NumOpenIssues,
160-
OpenPulls: repo.NumOpenPulls,
161-
Releases: int(numReleases),
162-
DefaultBranch: repo.DefaultBranch,
163-
Created: repo.CreatedUnix.AsTime(),
164-
Updated: repo.UpdatedUnix.AsTime(),
165-
Permissions: permission,
166-
HasIssues: hasIssues,
167-
ExternalTracker: externalTracker,
168-
InternalTracker: internalTracker,
169-
HasWiki: hasWiki,
170-
HasProjects: hasProjects,
171-
ExternalWiki: externalWiki,
172-
HasPullRequests: hasPullRequests,
173-
IgnoreWhitespaceConflicts: ignoreWhitespaceConflicts,
174-
AllowMerge: allowMerge,
175-
AllowRebase: allowRebase,
176-
AllowRebaseMerge: allowRebaseMerge,
177-
AllowSquash: allowSquash,
178-
DefaultMergeStyle: string(defaultMergeStyle),
179-
AvatarURL: repo.AvatarLink(),
180-
Internal: !repo.IsPrivate && repo.Owner.Visibility == api.VisibleTypePrivate,
181-
MirrorInterval: mirrorInterval,
182-
MirrorUpdated: mirrorUpdated,
183-
RepoTransfer: transfer,
140+
ID: repo.ID,
141+
Owner: ToUserWithAccessMode(repo.Owner, mode),
142+
Name: repo.Name,
143+
FullName: repo.FullName(),
144+
Description: repo.Description,
145+
Private: repo.IsPrivate,
146+
Template: repo.IsTemplate,
147+
Empty: repo.IsEmpty,
148+
Archived: repo.IsArchived,
149+
Size: int(repo.Size / 1024),
150+
Fork: repo.IsFork,
151+
Parent: parent,
152+
Mirror: repo.IsMirror,
153+
HTMLURL: repo.HTMLURL(),
154+
SSHURL: cloneLink.SSH,
155+
CloneURL: cloneLink.HTTPS,
156+
OriginalURL: repo.SanitizedOriginalURL(),
157+
Website: repo.Website,
158+
Language: language,
159+
LanguagesURL: repoAPIURL + "/languages",
160+
Stars: repo.NumStars,
161+
Forks: repo.NumForks,
162+
Watchers: repo.NumWatches,
163+
OpenIssues: repo.NumOpenIssues,
164+
OpenPulls: repo.NumOpenPulls,
165+
Releases: int(numReleases),
166+
DefaultBranch: repo.DefaultBranch,
167+
Created: repo.CreatedUnix.AsTime(),
168+
Updated: repo.UpdatedUnix.AsTime(),
169+
Permissions: permission,
170+
HasIssues: hasIssues,
171+
ExternalTracker: externalTracker,
172+
InternalTracker: internalTracker,
173+
HasWiki: hasWiki,
174+
HasProjects: hasProjects,
175+
ExternalWiki: externalWiki,
176+
HasPullRequests: hasPullRequests,
177+
IgnoreWhitespaceConflicts: ignoreWhitespaceConflicts,
178+
AllowMerge: allowMerge,
179+
AllowRebase: allowRebase,
180+
AllowRebaseMerge: allowRebaseMerge,
181+
AllowSquash: allowSquash,
182+
AllowRebaseUpdate: allowRebaseUpdate,
183+
DefaultDeleteBranchAfterMerge: defaultDeleteBranchAfterMerge,
184+
DefaultMergeStyle: string(defaultMergeStyle),
185+
AvatarURL: repo.AvatarLink(),
186+
Internal: !repo.IsPrivate && repo.Owner.Visibility == api.VisibleTypePrivate,
187+
MirrorInterval: mirrorInterval,
188+
MirrorUpdated: mirrorUpdated,
189+
RepoTransfer: transfer,
184190
}
185191
}
186192

modules/structs/repo.go

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,24 +77,26 @@ type Repository struct {
7777
// swagger:strfmt date-time
7878
Created time.Time `json:"created_at"`
7979
// swagger:strfmt date-time
80-
Updated time.Time `json:"updated_at"`
81-
Permissions *Permission `json:"permissions,omitempty"`
82-
HasIssues bool `json:"has_issues"`
83-
InternalTracker *InternalTracker `json:"internal_tracker,omitempty"`
84-
ExternalTracker *ExternalTracker `json:"external_tracker,omitempty"`
85-
HasWiki bool `json:"has_wiki"`
86-
ExternalWiki *ExternalWiki `json:"external_wiki,omitempty"`
87-
HasPullRequests bool `json:"has_pull_requests"`
88-
HasProjects bool `json:"has_projects"`
89-
IgnoreWhitespaceConflicts bool `json:"ignore_whitespace_conflicts"`
90-
AllowMerge bool `json:"allow_merge_commits"`
91-
AllowRebase bool `json:"allow_rebase"`
92-
AllowRebaseMerge bool `json:"allow_rebase_explicit"`
93-
AllowSquash bool `json:"allow_squash_merge"`
94-
DefaultMergeStyle string `json:"default_merge_style"`
95-
AvatarURL string `json:"avatar_url"`
96-
Internal bool `json:"internal"`
97-
MirrorInterval string `json:"mirror_interval"`
80+
Updated time.Time `json:"updated_at"`
81+
Permissions *Permission `json:"permissions,omitempty"`
82+
HasIssues bool `json:"has_issues"`
83+
InternalTracker *InternalTracker `json:"internal_tracker,omitempty"`
84+
ExternalTracker *ExternalTracker `json:"external_tracker,omitempty"`
85+
HasWiki bool `json:"has_wiki"`
86+
ExternalWiki *ExternalWiki `json:"external_wiki,omitempty"`
87+
HasPullRequests bool `json:"has_pull_requests"`
88+
HasProjects bool `json:"has_projects"`
89+
IgnoreWhitespaceConflicts bool `json:"ignore_whitespace_conflicts"`
90+
AllowMerge bool `json:"allow_merge_commits"`
91+
AllowRebase bool `json:"allow_rebase"`
92+
AllowRebaseMerge bool `json:"allow_rebase_explicit"`
93+
AllowSquash bool `json:"allow_squash_merge"`
94+
AllowRebaseUpdate bool `json:"allow_rebase_update"`
95+
DefaultDeleteBranchAfterMerge bool `json:"default_delete_branch_after_merge"`
96+
DefaultMergeStyle string `json:"default_merge_style"`
97+
AvatarURL string `json:"avatar_url"`
98+
Internal bool `json:"internal"`
99+
MirrorInterval string `json:"mirror_interval"`
98100
// swagger:strfmt date-time
99101
MirrorUpdated time.Time `json:"mirror_updated,omitempty"`
100102
RepoTransfer *RepoTransfer `json:"repo_transfer"`

templates/swagger/v1_json.tmpl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17713,6 +17713,10 @@
1771317713
"type": "boolean",
1771417714
"x-go-name": "AllowRebaseMerge"
1771517715
},
17716+
"allow_rebase_update": {
17717+
"type": "boolean",
17718+
"x-go-name": "AllowRebaseUpdate"
17719+
},
1771617720
"allow_squash_merge": {
1771717721
"type": "boolean",
1771817722
"x-go-name": "AllowSquash"
@@ -17738,6 +17742,10 @@
1773817742
"type": "string",
1773917743
"x-go-name": "DefaultBranch"
1774017744
},
17745+
"default_delete_branch_after_merge": {
17746+
"type": "boolean",
17747+
"x-go-name": "DefaultDeleteBranchAfterMerge"
17748+
},
1774117749
"default_merge_style": {
1774217750
"type": "string",
1774317751
"x-go-name": "DefaultMergeStyle"

0 commit comments

Comments
 (0)