Skip to content

Commit 574d8fe

Browse files
authored
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.
1 parent 8d9f8e1 commit 574d8fe

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed

modules/structs/repo.go

+9
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ type Repository struct {
8888
ExternalWiki *ExternalWiki `json:"external_wiki,omitempty"`
8989
HasPullRequests bool `json:"has_pull_requests"`
9090
HasProjects bool `json:"has_projects"`
91+
HasReleases bool `json:"has_releases"`
92+
HasPackages bool `json:"has_packages"`
93+
HasActions bool `json:"has_actions"`
9194
IgnoreWhitespaceConflicts bool `json:"ignore_whitespace_conflicts"`
9295
AllowMerge bool `json:"allow_merge_commits"`
9396
AllowRebase bool `json:"allow_rebase"`
@@ -168,6 +171,12 @@ type EditRepoOption struct {
168171
HasPullRequests *bool `json:"has_pull_requests,omitempty"`
169172
// either `true` to enable project unit, or `false` to disable them.
170173
HasProjects *bool `json:"has_projects,omitempty"`
174+
// either `true` to enable releases unit, or `false` to disable them.
175+
HasReleases *bool `json:"has_releases,omitempty"`
176+
// either `true` to enable packages unit, or `false` to disable them.
177+
HasPackages *bool `json:"has_packages,omitempty"`
178+
// either `true` to enable actions unit, or `false` to disable them.
179+
HasActions *bool `json:"has_actions,omitempty"`
171180
// either `true` to ignore whitespace for conflicts, or `false` to not ignore whitespace.
172181
IgnoreWhitespaceConflicts *bool `json:"ignore_whitespace_conflicts,omitempty"`
173182
// either `true` to allow merging pull requests with a merge commit, or `false` to prevent merging pull requests with merge commits.

routers/api/v1/repo/repo.go

+33
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,39 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
936936
}
937937
}
938938

939+
if opts.HasReleases != nil && !unit_model.TypeReleases.UnitGlobalDisabled() {
940+
if *opts.HasReleases {
941+
units = append(units, repo_model.RepoUnit{
942+
RepoID: repo.ID,
943+
Type: unit_model.TypeReleases,
944+
})
945+
} else {
946+
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeReleases)
947+
}
948+
}
949+
950+
if opts.HasPackages != nil && !unit_model.TypePackages.UnitGlobalDisabled() {
951+
if *opts.HasPackages {
952+
units = append(units, repo_model.RepoUnit{
953+
RepoID: repo.ID,
954+
Type: unit_model.TypePackages,
955+
})
956+
} else {
957+
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypePackages)
958+
}
959+
}
960+
961+
if opts.HasActions != nil && !unit_model.TypeActions.UnitGlobalDisabled() {
962+
if *opts.HasActions {
963+
units = append(units, repo_model.RepoUnit{
964+
RepoID: repo.ID,
965+
Type: unit_model.TypeActions,
966+
})
967+
} else {
968+
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeActions)
969+
}
970+
}
971+
939972
if err := repo_model.UpdateRepositoryUnits(repo, units, deleteUnitTypes); err != nil {
940973
ctx.Error(http.StatusInternalServerError, "UpdateRepositoryUnits", err)
941974
return err

services/convert/repository.go

+18
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,21 @@ func innerToRepo(ctx context.Context, repo *repo_model.Repository, mode perm.Acc
100100
hasProjects = true
101101
}
102102

103+
hasReleases := false
104+
if _, err := repo.GetUnit(ctx, unit_model.TypeReleases); err == nil {
105+
hasReleases = true
106+
}
107+
108+
hasPackages := false
109+
if _, err := repo.GetUnit(ctx, unit_model.TypePackages); err == nil {
110+
hasPackages = true
111+
}
112+
113+
hasActions := false
114+
if _, err := repo.GetUnit(ctx, unit_model.TypeActions); err == nil {
115+
hasActions = true
116+
}
117+
103118
if err := repo.LoadOwner(ctx); err != nil {
104119
return nil
105120
}
@@ -174,6 +189,9 @@ func innerToRepo(ctx context.Context, repo *repo_model.Repository, mode perm.Acc
174189
InternalTracker: internalTracker,
175190
HasWiki: hasWiki,
176191
HasProjects: hasProjects,
192+
HasReleases: hasReleases,
193+
HasPackages: hasPackages,
194+
HasActions: hasActions,
177195
ExternalWiki: externalWiki,
178196
HasPullRequests: hasPullRequests,
179197
IgnoreWhitespaceConflicts: ignoreWhitespaceConflicts,

templates/swagger/v1_json.tmpl

+27
Original file line numberDiff line numberDiff line change
@@ -16861,11 +16861,21 @@
1686116861
"external_wiki": {
1686216862
"$ref": "#/definitions/ExternalWiki"
1686316863
},
16864+
"has_actions": {
16865+
"description": "either `true` to enable actions unit, or `false` to disable them.",
16866+
"type": "boolean",
16867+
"x-go-name": "HasActions"
16868+
},
1686416869
"has_issues": {
1686516870
"description": "either `true` to enable issues for this repository or `false` to disable them.",
1686616871
"type": "boolean",
1686716872
"x-go-name": "HasIssues"
1686816873
},
16874+
"has_packages": {
16875+
"description": "either `true` to enable packages unit, or `false` to disable them.",
16876+
"type": "boolean",
16877+
"x-go-name": "HasPackages"
16878+
},
1686916879
"has_projects": {
1687016880
"description": "either `true` to enable project unit, or `false` to disable them.",
1687116881
"type": "boolean",
@@ -16876,6 +16886,11 @@
1687616886
"type": "boolean",
1687716887
"x-go-name": "HasPullRequests"
1687816888
},
16889+
"has_releases": {
16890+
"description": "either `true` to enable releases unit, or `false` to disable them.",
16891+
"type": "boolean",
16892+
"x-go-name": "HasReleases"
16893+
},
1687916894
"has_wiki": {
1688016895
"description": "either `true` to enable the wiki for this repository or `false` to disable it.",
1688116896
"type": "boolean",
@@ -19421,10 +19436,18 @@
1942119436
"type": "string",
1942219437
"x-go-name": "FullName"
1942319438
},
19439+
"has_actions": {
19440+
"type": "boolean",
19441+
"x-go-name": "HasActions"
19442+
},
1942419443
"has_issues": {
1942519444
"type": "boolean",
1942619445
"x-go-name": "HasIssues"
1942719446
},
19447+
"has_packages": {
19448+
"type": "boolean",
19449+
"x-go-name": "HasPackages"
19450+
},
1942819451
"has_projects": {
1942919452
"type": "boolean",
1943019453
"x-go-name": "HasProjects"
@@ -19433,6 +19456,10 @@
1943319456
"type": "boolean",
1943419457
"x-go-name": "HasPullRequests"
1943519458
},
19459+
"has_releases": {
19460+
"type": "boolean",
19461+
"x-go-name": "HasReleases"
19462+
},
1943619463
"has_wiki": {
1943719464
"type": "boolean",
1943819465
"x-go-name": "HasWiki"

0 commit comments

Comments
 (0)