mirror of
https://github.com/go-gitea/gitea.git
synced 2024-11-24 02:59:42 +08:00
Add absent repounits to create/edit repo API (#23500)
Adds the ability to enable/disable Actions, Packages and Releases from the API, via the Edit and Get Repository API endpoints.
This commit is contained in:
parent
8d9f8e10b1
commit
574d8fe6d6
@ -88,6 +88,9 @@ type Repository struct {
|
|||||||
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"`
|
||||||
|
HasReleases bool `json:"has_releases"`
|
||||||
|
HasPackages bool `json:"has_packages"`
|
||||||
|
HasActions bool `json:"has_actions"`
|
||||||
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"`
|
||||||
@ -168,6 +171,12 @@ type EditRepoOption struct {
|
|||||||
HasPullRequests *bool `json:"has_pull_requests,omitempty"`
|
HasPullRequests *bool `json:"has_pull_requests,omitempty"`
|
||||||
// either `true` to enable project unit, or `false` to disable them.
|
// either `true` to enable project unit, or `false` to disable them.
|
||||||
HasProjects *bool `json:"has_projects,omitempty"`
|
HasProjects *bool `json:"has_projects,omitempty"`
|
||||||
|
// either `true` to enable releases unit, or `false` to disable them.
|
||||||
|
HasReleases *bool `json:"has_releases,omitempty"`
|
||||||
|
// either `true` to enable packages unit, or `false` to disable them.
|
||||||
|
HasPackages *bool `json:"has_packages,omitempty"`
|
||||||
|
// either `true` to enable actions unit, or `false` to disable them.
|
||||||
|
HasActions *bool `json:"has_actions,omitempty"`
|
||||||
// either `true` to ignore whitespace for conflicts, or `false` to not ignore whitespace.
|
// either `true` to ignore whitespace for conflicts, or `false` to not ignore whitespace.
|
||||||
IgnoreWhitespaceConflicts *bool `json:"ignore_whitespace_conflicts,omitempty"`
|
IgnoreWhitespaceConflicts *bool `json:"ignore_whitespace_conflicts,omitempty"`
|
||||||
// either `true` to allow merging pull requests with a merge commit, or `false` to prevent merging pull requests with merge commits.
|
// either `true` to allow merging pull requests with a merge commit, or `false` to prevent merging pull requests with merge commits.
|
||||||
|
@ -936,6 +936,39 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if opts.HasReleases != nil && !unit_model.TypeReleases.UnitGlobalDisabled() {
|
||||||
|
if *opts.HasReleases {
|
||||||
|
units = append(units, repo_model.RepoUnit{
|
||||||
|
RepoID: repo.ID,
|
||||||
|
Type: unit_model.TypeReleases,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeReleases)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if opts.HasPackages != nil && !unit_model.TypePackages.UnitGlobalDisabled() {
|
||||||
|
if *opts.HasPackages {
|
||||||
|
units = append(units, repo_model.RepoUnit{
|
||||||
|
RepoID: repo.ID,
|
||||||
|
Type: unit_model.TypePackages,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypePackages)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if opts.HasActions != nil && !unit_model.TypeActions.UnitGlobalDisabled() {
|
||||||
|
if *opts.HasActions {
|
||||||
|
units = append(units, repo_model.RepoUnit{
|
||||||
|
RepoID: repo.ID,
|
||||||
|
Type: unit_model.TypeActions,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeActions)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err := repo_model.UpdateRepositoryUnits(repo, units, deleteUnitTypes); err != nil {
|
if err := repo_model.UpdateRepositoryUnits(repo, units, deleteUnitTypes); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateRepositoryUnits", err)
|
ctx.Error(http.StatusInternalServerError, "UpdateRepositoryUnits", err)
|
||||||
return err
|
return err
|
||||||
|
@ -100,6 +100,21 @@ func innerToRepo(ctx context.Context, repo *repo_model.Repository, mode perm.Acc
|
|||||||
hasProjects = true
|
hasProjects = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hasReleases := false
|
||||||
|
if _, err := repo.GetUnit(ctx, unit_model.TypeReleases); err == nil {
|
||||||
|
hasReleases = true
|
||||||
|
}
|
||||||
|
|
||||||
|
hasPackages := false
|
||||||
|
if _, err := repo.GetUnit(ctx, unit_model.TypePackages); err == nil {
|
||||||
|
hasPackages = true
|
||||||
|
}
|
||||||
|
|
||||||
|
hasActions := false
|
||||||
|
if _, err := repo.GetUnit(ctx, unit_model.TypeActions); err == nil {
|
||||||
|
hasActions = true
|
||||||
|
}
|
||||||
|
|
||||||
if err := repo.LoadOwner(ctx); err != nil {
|
if err := repo.LoadOwner(ctx); err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -174,6 +189,9 @@ func innerToRepo(ctx context.Context, repo *repo_model.Repository, mode perm.Acc
|
|||||||
InternalTracker: internalTracker,
|
InternalTracker: internalTracker,
|
||||||
HasWiki: hasWiki,
|
HasWiki: hasWiki,
|
||||||
HasProjects: hasProjects,
|
HasProjects: hasProjects,
|
||||||
|
HasReleases: hasReleases,
|
||||||
|
HasPackages: hasPackages,
|
||||||
|
HasActions: hasActions,
|
||||||
ExternalWiki: externalWiki,
|
ExternalWiki: externalWiki,
|
||||||
HasPullRequests: hasPullRequests,
|
HasPullRequests: hasPullRequests,
|
||||||
IgnoreWhitespaceConflicts: ignoreWhitespaceConflicts,
|
IgnoreWhitespaceConflicts: ignoreWhitespaceConflicts,
|
||||||
|
@ -16861,11 +16861,21 @@
|
|||||||
"external_wiki": {
|
"external_wiki": {
|
||||||
"$ref": "#/definitions/ExternalWiki"
|
"$ref": "#/definitions/ExternalWiki"
|
||||||
},
|
},
|
||||||
|
"has_actions": {
|
||||||
|
"description": "either `true` to enable actions unit, or `false` to disable them.",
|
||||||
|
"type": "boolean",
|
||||||
|
"x-go-name": "HasActions"
|
||||||
|
},
|
||||||
"has_issues": {
|
"has_issues": {
|
||||||
"description": "either `true` to enable issues for this repository or `false` to disable them.",
|
"description": "either `true` to enable issues for this repository or `false` to disable them.",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"x-go-name": "HasIssues"
|
"x-go-name": "HasIssues"
|
||||||
},
|
},
|
||||||
|
"has_packages": {
|
||||||
|
"description": "either `true` to enable packages unit, or `false` to disable them.",
|
||||||
|
"type": "boolean",
|
||||||
|
"x-go-name": "HasPackages"
|
||||||
|
},
|
||||||
"has_projects": {
|
"has_projects": {
|
||||||
"description": "either `true` to enable project unit, or `false` to disable them.",
|
"description": "either `true` to enable project unit, or `false` to disable them.",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
@ -16876,6 +16886,11 @@
|
|||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"x-go-name": "HasPullRequests"
|
"x-go-name": "HasPullRequests"
|
||||||
},
|
},
|
||||||
|
"has_releases": {
|
||||||
|
"description": "either `true` to enable releases unit, or `false` to disable them.",
|
||||||
|
"type": "boolean",
|
||||||
|
"x-go-name": "HasReleases"
|
||||||
|
},
|
||||||
"has_wiki": {
|
"has_wiki": {
|
||||||
"description": "either `true` to enable the wiki for this repository or `false` to disable it.",
|
"description": "either `true` to enable the wiki for this repository or `false` to disable it.",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
@ -19421,10 +19436,18 @@
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"x-go-name": "FullName"
|
"x-go-name": "FullName"
|
||||||
},
|
},
|
||||||
|
"has_actions": {
|
||||||
|
"type": "boolean",
|
||||||
|
"x-go-name": "HasActions"
|
||||||
|
},
|
||||||
"has_issues": {
|
"has_issues": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"x-go-name": "HasIssues"
|
"x-go-name": "HasIssues"
|
||||||
},
|
},
|
||||||
|
"has_packages": {
|
||||||
|
"type": "boolean",
|
||||||
|
"x-go-name": "HasPackages"
|
||||||
|
},
|
||||||
"has_projects": {
|
"has_projects": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"x-go-name": "HasProjects"
|
"x-go-name": "HasProjects"
|
||||||
@ -19433,6 +19456,10 @@
|
|||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"x-go-name": "HasPullRequests"
|
"x-go-name": "HasPullRequests"
|
||||||
},
|
},
|
||||||
|
"has_releases": {
|
||||||
|
"type": "boolean",
|
||||||
|
"x-go-name": "HasReleases"
|
||||||
|
},
|
||||||
"has_wiki": {
|
"has_wiki": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"x-go-name": "HasWiki"
|
"x-go-name": "HasWiki"
|
||||||
|
Loading…
Reference in New Issue
Block a user