Skip to content

Commit db7ba91

Browse files
committed
Add has_code to repository REST API
1 parent 1692652 commit db7ba91

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

modules/structs/repo.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ type Repository struct {
8484
Updated time.Time `json:"updated_at"`
8585
ArchivedAt time.Time `json:"archived_at"`
8686
Permissions *Permission `json:"permissions,omitempty"`
87+
HasCode bool `json:"has_code"`
8788
HasIssues bool `json:"has_issues"`
8889
InternalTracker *InternalTracker `json:"internal_tracker,omitempty"`
8990
ExternalTracker *ExternalTracker `json:"external_tracker,omitempty"`
@@ -170,6 +171,8 @@ type EditRepoOption struct {
170171
Private *bool `json:"private,omitempty"`
171172
// either `true` to make this repository a template or `false` to make it a normal repository
172173
Template *bool `json:"template,omitempty"`
174+
// either `true` to enable code for this repository or `false` to disable it.
175+
HasCode *bool `json:"has_code,omitempty"`
173176
// either `true` to enable issues for this repository or `false` to disable them.
174177
HasIssues *bool `json:"has_issues,omitempty"`
175178
// set this structure to configure internal issue tracker

routers/api/v1/repo/repo.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,23 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
879879
}
880880
}
881881

882+
currHasCode := repo.UnitEnabled(ctx, unit_model.TypeCode)
883+
newHasCode := currHasCode
884+
if opts.HasCode != nil {
885+
newHasCode = *opts.HasCode
886+
}
887+
if currHasCode || newHasCode {
888+
if newHasCode && !unit_model.TypeCode.UnitGlobalDisabled() {
889+
units = append(units, repo_model.RepoUnit{
890+
RepoID: repo.ID,
891+
Type: unit_model.TypeCode,
892+
Config: &repo_model.UnitConfig{},
893+
})
894+
} else if !newHasCode && !unit_model.TypeCode.UnitGlobalDisabled() {
895+
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeCode)
896+
}
897+
}
898+
882899
currHasPullRequests := repo.UnitEnabled(ctx, unit_model.TypePullRequests)
883900
newHasPullRequests := currHasPullRequests
884901
if opts.HasPullRequests != nil {

templates/swagger/v1_json.tmpl

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)