mirror of
https://github.com/go-gitea/gitea.git
synced 2025-08-11 11:03:28 +00:00
Add has_code
to repository REST API (#35214)
similar to how we can enable/disable repos or issues on a repo add the code unit as option to it. affects ``` PATCH /repos/{owner}/{repo} ``` --- *Sponsored by Kithara Software GmbH*
This commit is contained in:
parent
793815adf7
commit
ef613ee760
@ -84,6 +84,7 @@ type Repository struct {
|
|||||||
Updated time.Time `json:"updated_at"`
|
Updated time.Time `json:"updated_at"`
|
||||||
ArchivedAt time.Time `json:"archived_at"`
|
ArchivedAt time.Time `json:"archived_at"`
|
||||||
Permissions *Permission `json:"permissions,omitempty"`
|
Permissions *Permission `json:"permissions,omitempty"`
|
||||||
|
HasCode bool `json:"has_code"`
|
||||||
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"`
|
||||||
@ -170,6 +171,8 @@ type EditRepoOption struct {
|
|||||||
Private *bool `json:"private,omitempty"`
|
Private *bool `json:"private,omitempty"`
|
||||||
// either `true` to make this repository a template or `false` to make it a normal repository
|
// either `true` to make this repository a template or `false` to make it a normal repository
|
||||||
Template *bool `json:"template,omitempty"`
|
Template *bool `json:"template,omitempty"`
|
||||||
|
// either `true` to enable code for this repository or `false` to disable it.
|
||||||
|
HasCode *bool `json:"has_code,omitempty"`
|
||||||
// either `true` to enable issues for this repository or `false` to disable them.
|
// either `true` to enable issues for this repository or `false` to disable them.
|
||||||
HasIssues *bool `json:"has_issues,omitempty"`
|
HasIssues *bool `json:"has_issues,omitempty"`
|
||||||
// set this structure to configure internal issue tracker
|
// set this structure to configure internal issue tracker
|
||||||
|
@ -869,6 +869,18 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if opts.HasCode != nil && !unit_model.TypeCode.UnitGlobalDisabled() {
|
||||||
|
if *opts.HasCode {
|
||||||
|
units = append(units, repo_model.RepoUnit{
|
||||||
|
RepoID: repo.ID,
|
||||||
|
Type: unit_model.TypeCode,
|
||||||
|
Config: &repo_model.UnitConfig{},
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeCode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if opts.HasPullRequests != nil && !unit_model.TypePullRequests.UnitGlobalDisabled() {
|
if opts.HasPullRequests != nil && !unit_model.TypePullRequests.UnitGlobalDisabled() {
|
||||||
if *opts.HasPullRequests {
|
if *opts.HasPullRequests {
|
||||||
// We do allow setting individual PR settings through the API, so
|
// We do allow setting individual PR settings through the API, so
|
||||||
|
9
templates/swagger/v1_json.tmpl
generated
9
templates/swagger/v1_json.tmpl
generated
@ -24333,6 +24333,11 @@
|
|||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"x-go-name": "HasActions"
|
"x-go-name": "HasActions"
|
||||||
},
|
},
|
||||||
|
"has_code": {
|
||||||
|
"description": "either `true` to enable code for this repository or `false` to disable it.",
|
||||||
|
"type": "boolean",
|
||||||
|
"x-go-name": "HasCode"
|
||||||
|
},
|
||||||
"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",
|
||||||
@ -27375,6 +27380,10 @@
|
|||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"x-go-name": "HasActions"
|
"x-go-name": "HasActions"
|
||||||
},
|
},
|
||||||
|
"has_code": {
|
||||||
|
"type": "boolean",
|
||||||
|
"x-go-name": "HasCode"
|
||||||
|
},
|
||||||
"has_issues": {
|
"has_issues": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"x-go-name": "HasIssues"
|
"x-go-name": "HasIssues"
|
||||||
|
@ -76,12 +76,36 @@ func getRepoEditOptionFromRepo(repo *repo_model.Repository) *api.EditRepoOption
|
|||||||
allowFastForwardOnly = config.AllowFastForwardOnly
|
allowFastForwardOnly = config.AllowFastForwardOnly
|
||||||
}
|
}
|
||||||
archived := repo.IsArchived
|
archived := repo.IsArchived
|
||||||
|
hasProjects := false
|
||||||
|
var projectsMode *string
|
||||||
|
if unit, err := repo.GetUnit(db.DefaultContext, unit_model.TypeProjects); err == nil && unit != nil {
|
||||||
|
hasProjects = true
|
||||||
|
pm := string(unit.ProjectsConfig().ProjectsMode)
|
||||||
|
projectsMode = &pm
|
||||||
|
}
|
||||||
|
hasCode := repo.UnitEnabled(db.DefaultContext, unit_model.TypeCode)
|
||||||
|
hasPackages := repo.UnitEnabled(db.DefaultContext, unit_model.TypePackages)
|
||||||
|
hasReleases := repo.UnitEnabled(db.DefaultContext, unit_model.TypeReleases)
|
||||||
|
hasActions := false
|
||||||
|
if unit, err := repo.GetUnit(db.DefaultContext, unit_model.TypeActions); err == nil && unit != nil {
|
||||||
|
hasActions = true
|
||||||
|
// TODO: expose action config of repo to api
|
||||||
|
// actionsConfig = &api.RepoActionsConfig{
|
||||||
|
// DisabledWorkflows: unit.ActionsConfig().DisabledWorkflows,
|
||||||
|
// }
|
||||||
|
}
|
||||||
return &api.EditRepoOption{
|
return &api.EditRepoOption{
|
||||||
Name: &name,
|
Name: &name,
|
||||||
Description: &description,
|
Description: &description,
|
||||||
Website: &website,
|
Website: &website,
|
||||||
Private: &private,
|
Private: &private,
|
||||||
HasIssues: &hasIssues,
|
HasIssues: &hasIssues,
|
||||||
|
HasProjects: &hasProjects,
|
||||||
|
ProjectsMode: projectsMode,
|
||||||
|
HasCode: &hasCode,
|
||||||
|
HasPackages: &hasPackages,
|
||||||
|
HasReleases: &hasReleases,
|
||||||
|
HasActions: &hasActions,
|
||||||
ExternalTracker: externalTracker,
|
ExternalTracker: externalTracker,
|
||||||
InternalTracker: internalTracker,
|
InternalTracker: internalTracker,
|
||||||
HasWiki: &hasWiki,
|
HasWiki: &hasWiki,
|
||||||
@ -108,6 +132,11 @@ func getNewRepoEditOption(opts *api.EditRepoOption) *api.EditRepoOption {
|
|||||||
private := !*opts.Private
|
private := !*opts.Private
|
||||||
hasIssues := !*opts.HasIssues
|
hasIssues := !*opts.HasIssues
|
||||||
hasWiki := !*opts.HasWiki
|
hasWiki := !*opts.HasWiki
|
||||||
|
hasProjects := !*opts.HasProjects
|
||||||
|
hasCode := !*opts.HasCode
|
||||||
|
hasPackages := !*opts.HasPackages
|
||||||
|
hasReleases := !*opts.HasReleases
|
||||||
|
hasActions := !*opts.HasActions
|
||||||
defaultBranch := "master"
|
defaultBranch := "master"
|
||||||
hasPullRequests := !*opts.HasPullRequests
|
hasPullRequests := !*opts.HasPullRequests
|
||||||
ignoreWhitespaceConflicts := !*opts.IgnoreWhitespaceConflicts
|
ignoreWhitespaceConflicts := !*opts.IgnoreWhitespaceConflicts
|
||||||
@ -125,6 +154,11 @@ func getNewRepoEditOption(opts *api.EditRepoOption) *api.EditRepoOption {
|
|||||||
DefaultBranch: &defaultBranch,
|
DefaultBranch: &defaultBranch,
|
||||||
HasIssues: &hasIssues,
|
HasIssues: &hasIssues,
|
||||||
HasWiki: &hasWiki,
|
HasWiki: &hasWiki,
|
||||||
|
HasProjects: &hasProjects,
|
||||||
|
HasCode: &hasCode,
|
||||||
|
HasPackages: &hasPackages,
|
||||||
|
HasReleases: &hasReleases,
|
||||||
|
HasActions: &hasActions,
|
||||||
HasPullRequests: &hasPullRequests,
|
HasPullRequests: &hasPullRequests,
|
||||||
IgnoreWhitespaceConflicts: &ignoreWhitespaceConflicts,
|
IgnoreWhitespaceConflicts: &ignoreWhitespaceConflicts,
|
||||||
AllowMerge: &allowMerge,
|
AllowMerge: &allowMerge,
|
||||||
@ -156,6 +190,11 @@ func TestAPIRepoEdit(t *testing.T) {
|
|||||||
|
|
||||||
// Test editing a repo1 which user2 owns, changing name and many properties
|
// Test editing a repo1 which user2 owns, changing name and many properties
|
||||||
origRepoEditOption := getRepoEditOptionFromRepo(repo1)
|
origRepoEditOption := getRepoEditOptionFromRepo(repo1)
|
||||||
|
assert.True(t, *origRepoEditOption.HasCode)
|
||||||
|
assert.True(t, *origRepoEditOption.HasPackages)
|
||||||
|
assert.True(t, *origRepoEditOption.HasProjects)
|
||||||
|
assert.True(t, *origRepoEditOption.HasReleases)
|
||||||
|
assert.True(t, *origRepoEditOption.HasActions)
|
||||||
repoEditOption := getNewRepoEditOption(origRepoEditOption)
|
repoEditOption := getNewRepoEditOption(origRepoEditOption)
|
||||||
req := NewRequestWithJSON(t, "PATCH", fmt.Sprintf("/api/v1/repos/%s/%s", user2.Name, repo1.Name), &repoEditOption).
|
req := NewRequestWithJSON(t, "PATCH", fmt.Sprintf("/api/v1/repos/%s/%s", user2.Name, repo1.Name), &repoEditOption).
|
||||||
AddTokenAuth(token2)
|
AddTokenAuth(token2)
|
||||||
@ -177,6 +216,11 @@ func TestAPIRepoEdit(t *testing.T) {
|
|||||||
assert.Equal(t, *repoEditOption.Archived, *repo1editedOption.Archived)
|
assert.Equal(t, *repoEditOption.Archived, *repo1editedOption.Archived)
|
||||||
assert.Equal(t, *repoEditOption.Private, *repo1editedOption.Private)
|
assert.Equal(t, *repoEditOption.Private, *repo1editedOption.Private)
|
||||||
assert.Equal(t, *repoEditOption.HasWiki, *repo1editedOption.HasWiki)
|
assert.Equal(t, *repoEditOption.HasWiki, *repo1editedOption.HasWiki)
|
||||||
|
assert.Equal(t, *repoEditOption.HasCode, *repo1editedOption.HasCode)
|
||||||
|
assert.Equal(t, *repoEditOption.HasPackages, *repo1editedOption.HasPackages)
|
||||||
|
assert.Equal(t, *repoEditOption.HasProjects, *repo1editedOption.HasProjects)
|
||||||
|
assert.Equal(t, *repoEditOption.HasReleases, *repo1editedOption.HasReleases)
|
||||||
|
assert.Equal(t, *repoEditOption.HasActions, *repo1editedOption.HasActions)
|
||||||
|
|
||||||
// Test editing repo1 to use internal issue and wiki (default)
|
// Test editing repo1 to use internal issue and wiki (default)
|
||||||
*repoEditOption.HasIssues = true
|
*repoEditOption.HasIssues = true
|
||||||
@ -224,6 +268,11 @@ func TestAPIRepoEdit(t *testing.T) {
|
|||||||
assert.Equal(t, *repo1editedOption.ExternalTracker, *repoEditOption.ExternalTracker)
|
assert.Equal(t, *repo1editedOption.ExternalTracker, *repoEditOption.ExternalTracker)
|
||||||
assert.True(t, *repo1editedOption.HasWiki)
|
assert.True(t, *repo1editedOption.HasWiki)
|
||||||
assert.Equal(t, *repo1editedOption.ExternalWiki, *repoEditOption.ExternalWiki)
|
assert.Equal(t, *repo1editedOption.ExternalWiki, *repoEditOption.ExternalWiki)
|
||||||
|
assert.False(t, *repo1editedOption.HasCode)
|
||||||
|
assert.False(t, *repo1editedOption.HasPackages)
|
||||||
|
assert.False(t, *repo1editedOption.HasProjects)
|
||||||
|
assert.False(t, *repo1editedOption.HasReleases)
|
||||||
|
assert.False(t, *repo1editedOption.HasActions)
|
||||||
|
|
||||||
repoEditOption.ExternalTracker.ExternalTrackerStyle = "regexp"
|
repoEditOption.ExternalTracker.ExternalTrackerStyle = "regexp"
|
||||||
repoEditOption.ExternalTracker.ExternalTrackerRegexpPattern = `(\d+)`
|
repoEditOption.ExternalTracker.ExternalTrackerRegexpPattern = `(\d+)`
|
||||||
@ -272,6 +321,11 @@ func TestAPIRepoEdit(t *testing.T) {
|
|||||||
assert.NotNil(t, *repo1editedOption.ExternalTracker)
|
assert.NotNil(t, *repo1editedOption.ExternalTracker)
|
||||||
assert.True(t, *repo1editedOption.HasWiki)
|
assert.True(t, *repo1editedOption.HasWiki)
|
||||||
assert.NotNil(t, *repo1editedOption.ExternalWiki)
|
assert.NotNil(t, *repo1editedOption.ExternalWiki)
|
||||||
|
assert.False(t, *repo1editedOption.HasCode)
|
||||||
|
assert.False(t, *repo1editedOption.HasPackages)
|
||||||
|
assert.False(t, *repo1editedOption.HasProjects)
|
||||||
|
assert.False(t, *repo1editedOption.HasReleases)
|
||||||
|
assert.False(t, *repo1editedOption.HasActions)
|
||||||
|
|
||||||
// reset repo in db
|
// reset repo in db
|
||||||
req = NewRequestWithJSON(t, "PATCH", fmt.Sprintf("/api/v1/repos/%s/%s", user2.Name, *repoEditOption.Name), &origRepoEditOption).
|
req = NewRequestWithJSON(t, "PATCH", fmt.Sprintf("/api/v1/repos/%s/%s", user2.Name, *repoEditOption.Name), &origRepoEditOption).
|
||||||
|
Loading…
Reference in New Issue
Block a user