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.
This commit is contained in:
Bian Jiaping 2022-07-15 16:00:01 +08:00 committed by GitHub
parent edd945bca3
commit e49ef56dde
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 82 additions and 66 deletions

View file

@ -78,6 +78,8 @@ func innerToRepo(repo *repo_model.Repository, mode perm.AccessMode, isParent boo
allowRebase := false allowRebase := false
allowRebaseMerge := false allowRebaseMerge := false
allowSquash := false allowSquash := false
allowRebaseUpdate := false
defaultDeleteBranchAfterMerge := false
defaultMergeStyle := repo_model.MergeStyleMerge defaultMergeStyle := repo_model.MergeStyleMerge
if unit, err := repo.GetUnit(unit_model.TypePullRequests); err == nil { if unit, err := repo.GetUnit(unit_model.TypePullRequests); err == nil {
config := unit.PullRequestsConfig() config := unit.PullRequestsConfig()
@ -87,6 +89,8 @@ func innerToRepo(repo *repo_model.Repository, mode perm.AccessMode, isParent boo
allowRebase = config.AllowRebase allowRebase = config.AllowRebase
allowRebaseMerge = config.AllowRebaseMerge allowRebaseMerge = config.AllowRebaseMerge
allowSquash = config.AllowSquash allowSquash = config.AllowSquash
allowRebaseUpdate = config.AllowRebaseUpdate
defaultDeleteBranchAfterMerge = config.DefaultDeleteBranchAfterMerge
defaultMergeStyle = config.GetDefaultMergeStyle() defaultMergeStyle = config.GetDefaultMergeStyle()
} }
hasProjects := false hasProjects := false
@ -133,54 +137,56 @@ func innerToRepo(repo *repo_model.Repository, mode perm.AccessMode, isParent boo
repoAPIURL := repo.APIURL() repoAPIURL := repo.APIURL()
return &api.Repository{ return &api.Repository{
ID: repo.ID, ID: repo.ID,
Owner: ToUserWithAccessMode(repo.Owner, mode), Owner: ToUserWithAccessMode(repo.Owner, mode),
Name: repo.Name, Name: repo.Name,
FullName: repo.FullName(), FullName: repo.FullName(),
Description: repo.Description, Description: repo.Description,
Private: repo.IsPrivate, Private: repo.IsPrivate,
Template: repo.IsTemplate, Template: repo.IsTemplate,
Empty: repo.IsEmpty, Empty: repo.IsEmpty,
Archived: repo.IsArchived, Archived: repo.IsArchived,
Size: int(repo.Size / 1024), Size: int(repo.Size / 1024),
Fork: repo.IsFork, Fork: repo.IsFork,
Parent: parent, Parent: parent,
Mirror: repo.IsMirror, Mirror: repo.IsMirror,
HTMLURL: repo.HTMLURL(), HTMLURL: repo.HTMLURL(),
SSHURL: cloneLink.SSH, SSHURL: cloneLink.SSH,
CloneURL: cloneLink.HTTPS, CloneURL: cloneLink.HTTPS,
OriginalURL: repo.SanitizedOriginalURL(), OriginalURL: repo.SanitizedOriginalURL(),
Website: repo.Website, Website: repo.Website,
Language: language, Language: language,
LanguagesURL: repoAPIURL + "/languages", LanguagesURL: repoAPIURL + "/languages",
Stars: repo.NumStars, Stars: repo.NumStars,
Forks: repo.NumForks, Forks: repo.NumForks,
Watchers: repo.NumWatches, Watchers: repo.NumWatches,
OpenIssues: repo.NumOpenIssues, OpenIssues: repo.NumOpenIssues,
OpenPulls: repo.NumOpenPulls, OpenPulls: repo.NumOpenPulls,
Releases: int(numReleases), Releases: int(numReleases),
DefaultBranch: repo.DefaultBranch, DefaultBranch: repo.DefaultBranch,
Created: repo.CreatedUnix.AsTime(), Created: repo.CreatedUnix.AsTime(),
Updated: repo.UpdatedUnix.AsTime(), Updated: repo.UpdatedUnix.AsTime(),
Permissions: permission, Permissions: permission,
HasIssues: hasIssues, HasIssues: hasIssues,
ExternalTracker: externalTracker, ExternalTracker: externalTracker,
InternalTracker: internalTracker, InternalTracker: internalTracker,
HasWiki: hasWiki, HasWiki: hasWiki,
HasProjects: hasProjects, HasProjects: hasProjects,
ExternalWiki: externalWiki, ExternalWiki: externalWiki,
HasPullRequests: hasPullRequests, HasPullRequests: hasPullRequests,
IgnoreWhitespaceConflicts: ignoreWhitespaceConflicts, IgnoreWhitespaceConflicts: ignoreWhitespaceConflicts,
AllowMerge: allowMerge, AllowMerge: allowMerge,
AllowRebase: allowRebase, AllowRebase: allowRebase,
AllowRebaseMerge: allowRebaseMerge, AllowRebaseMerge: allowRebaseMerge,
AllowSquash: allowSquash, AllowSquash: allowSquash,
DefaultMergeStyle: string(defaultMergeStyle), AllowRebaseUpdate: allowRebaseUpdate,
AvatarURL: repo.AvatarLink(), DefaultDeleteBranchAfterMerge: defaultDeleteBranchAfterMerge,
Internal: !repo.IsPrivate && repo.Owner.Visibility == api.VisibleTypePrivate, DefaultMergeStyle: string(defaultMergeStyle),
MirrorInterval: mirrorInterval, AvatarURL: repo.AvatarLink(),
MirrorUpdated: mirrorUpdated, Internal: !repo.IsPrivate && repo.Owner.Visibility == api.VisibleTypePrivate,
RepoTransfer: transfer, MirrorInterval: mirrorInterval,
MirrorUpdated: mirrorUpdated,
RepoTransfer: transfer,
} }
} }

View file

@ -77,24 +77,26 @@ type Repository struct {
// swagger:strfmt date-time // swagger:strfmt date-time
Created time.Time `json:"created_at"` Created time.Time `json:"created_at"`
// swagger:strfmt date-time // swagger:strfmt date-time
Updated time.Time `json:"updated_at"` Updated time.Time `json:"updated_at"`
Permissions *Permission `json:"permissions,omitempty"` Permissions *Permission `json:"permissions,omitempty"`
HasIssues bool `json:"has_issues"` HasIssues bool `json:"has_issues"`
InternalTracker *InternalTracker `json:"internal_tracker,omitempty"` InternalTracker *InternalTracker `json:"internal_tracker,omitempty"`
ExternalTracker *ExternalTracker `json:"external_tracker,omitempty"` ExternalTracker *ExternalTracker `json:"external_tracker,omitempty"`
HasWiki bool `json:"has_wiki"` HasWiki bool `json:"has_wiki"`
ExternalWiki *ExternalWiki `json:"external_wiki,omitempty"` ExternalWiki *ExternalWiki `json:"external_wiki,omitempty"`
HasPullRequests bool `json:"has_pull_requests"` HasPullRequests bool `json:"has_pull_requests"`
HasProjects bool `json:"has_projects"` HasProjects bool `json:"has_projects"`
IgnoreWhitespaceConflicts bool `json:"ignore_whitespace_conflicts"` IgnoreWhitespaceConflicts bool `json:"ignore_whitespace_conflicts"`
AllowMerge bool `json:"allow_merge_commits"` AllowMerge bool `json:"allow_merge_commits"`
AllowRebase bool `json:"allow_rebase"` AllowRebase bool `json:"allow_rebase"`
AllowRebaseMerge bool `json:"allow_rebase_explicit"` AllowRebaseMerge bool `json:"allow_rebase_explicit"`
AllowSquash bool `json:"allow_squash_merge"` AllowSquash bool `json:"allow_squash_merge"`
DefaultMergeStyle string `json:"default_merge_style"` AllowRebaseUpdate bool `json:"allow_rebase_update"`
AvatarURL string `json:"avatar_url"` DefaultDeleteBranchAfterMerge bool `json:"default_delete_branch_after_merge"`
Internal bool `json:"internal"` DefaultMergeStyle string `json:"default_merge_style"`
MirrorInterval string `json:"mirror_interval"` AvatarURL string `json:"avatar_url"`
Internal bool `json:"internal"`
MirrorInterval string `json:"mirror_interval"`
// swagger:strfmt date-time // swagger:strfmt date-time
MirrorUpdated time.Time `json:"mirror_updated,omitempty"` MirrorUpdated time.Time `json:"mirror_updated,omitempty"`
RepoTransfer *RepoTransfer `json:"repo_transfer"` RepoTransfer *RepoTransfer `json:"repo_transfer"`

View file

@ -17713,6 +17713,10 @@
"type": "boolean", "type": "boolean",
"x-go-name": "AllowRebaseMerge" "x-go-name": "AllowRebaseMerge"
}, },
"allow_rebase_update": {
"type": "boolean",
"x-go-name": "AllowRebaseUpdate"
},
"allow_squash_merge": { "allow_squash_merge": {
"type": "boolean", "type": "boolean",
"x-go-name": "AllowSquash" "x-go-name": "AllowSquash"
@ -17738,6 +17742,10 @@
"type": "string", "type": "string",
"x-go-name": "DefaultBranch" "x-go-name": "DefaultBranch"
}, },
"default_delete_branch_after_merge": {
"type": "boolean",
"x-go-name": "DefaultDeleteBranchAfterMerge"
},
"default_merge_style": { "default_merge_style": {
"type": "string", "type": "string",
"x-go-name": "DefaultMergeStyle" "x-go-name": "DefaultMergeStyle"