Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make external issue tracker regexp configurable via API #21338

Merged
merged 3 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions modules/convert/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ func innerToRepo(repo *repo_model.Repository, mode perm.AccessMode, isParent boo
config := unit.ExternalTrackerConfig()
hasIssues = true
externalTracker = &api.ExternalTracker{
ExternalTrackerURL: config.ExternalTrackerURL,
ExternalTrackerFormat: config.ExternalTrackerFormat,
ExternalTrackerStyle: config.ExternalTrackerStyle,
ExternalTrackerURL: config.ExternalTrackerURL,
ExternalTrackerFormat: config.ExternalTrackerFormat,
ExternalTrackerStyle: config.ExternalTrackerStyle,
ExternalTrackerRegexpPattern: config.ExternalTrackerRegexpPattern,
}
}
hasWiki := false
Expand Down
4 changes: 3 additions & 1 deletion modules/structs/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ type ExternalTracker struct {
ExternalTrackerURL string `json:"external_tracker_url"`
// External Issue Tracker URL Format. Use the placeholders {user}, {repo} and {index} for the username, repository name and issue index.
ExternalTrackerFormat string `json:"external_tracker_format"`
// External Issue Tracker Number Format, either `numeric` or `alphanumeric`
// External Issue Tracker Number Format, either `numeric`, `alphanumeric`, or `regexp`
ExternalTrackerStyle string `json:"external_tracker_style"`
// External Issue Tracker issue regular expression
ExternalTrackerRegexpPattern string `json:"external_tracker_regexp_pattern"`
}

// ExternalWiki represents setting for external wiki
Expand Down
7 changes: 4 additions & 3 deletions routers/api/v1/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -755,9 +755,10 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
RepoID: repo.ID,
Type: unit_model.TypeExternalTracker,
Config: &repo_model.ExternalTrackerConfig{
ExternalTrackerURL: opts.ExternalTracker.ExternalTrackerURL,
ExternalTrackerFormat: opts.ExternalTracker.ExternalTrackerFormat,
ExternalTrackerStyle: opts.ExternalTracker.ExternalTrackerStyle,
ExternalTrackerURL: opts.ExternalTracker.ExternalTrackerURL,
ExternalTrackerFormat: opts.ExternalTracker.ExternalTrackerFormat,
ExternalTrackerStyle: opts.ExternalTracker.ExternalTrackerStyle,
ExternalTrackerRegexpPattern: opts.ExternalTracker.ExternalTrackerRegexpPattern,
},
})
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeIssues)
Expand Down
7 changes: 6 additions & 1 deletion templates/swagger/v1_json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -16015,8 +16015,13 @@
"type": "string",
"x-go-name": "ExternalTrackerFormat"
},
"external_tracker_regexp_pattern": {
"description": "External Issue Tracker issue regular expression",
"type": "string",
"x-go-name": "ExternalTrackerRegexpPattern"
},
"external_tracker_style": {
"description": "External Issue Tracker Number Format, either `numeric` or `alphanumeric`",
"description": "External Issue Tracker Number Format, either `numeric`, `alphanumeric`, or `regexp`",
"type": "string",
"x-go-name": "ExternalTrackerStyle"
},
Expand Down
18 changes: 15 additions & 3 deletions tests/integration/api_repo_edit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ func getRepoEditOptionFromRepo(repo *repo_model.Repository) *api.EditRepoOption
config := unit.ExternalTrackerConfig()
hasIssues = true
externalTracker = &api.ExternalTracker{
ExternalTrackerURL: config.ExternalTrackerURL,
ExternalTrackerFormat: config.ExternalTrackerFormat,
ExternalTrackerStyle: config.ExternalTrackerStyle,
ExternalTrackerURL: config.ExternalTrackerURL,
ExternalTrackerFormat: config.ExternalTrackerFormat,
ExternalTrackerStyle: config.ExternalTrackerStyle,
ExternalTrackerRegexpPattern: config.ExternalTrackerRegexpPattern,
}
}
hasWiki := false
Expand Down Expand Up @@ -220,6 +221,17 @@ func TestAPIRepoEdit(t *testing.T) {
assert.Equal(t, *repo1editedOption.HasWiki, true)
assert.Equal(t, *repo1editedOption.ExternalWiki, *repoEditOption.ExternalWiki)

repoEditOption.ExternalTracker.ExternalTrackerStyle = "regexp"
repoEditOption.ExternalTracker.ExternalTrackerRegexpPattern = `(\d+)`
req = NewRequestWithJSON(t, "PATCH", url, &repoEditOption)
resp = session.MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &repo)
assert.NotNil(t, repo)
repo1edited = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
repo1editedOption = getRepoEditOptionFromRepo(repo1edited)
assert.Equal(t, *repo1editedOption.HasIssues, true)
assert.Equal(t, *repo1editedOption.ExternalTracker, *repoEditOption.ExternalTracker)

// Do some tests with invalid URL for external tracker and wiki
repoEditOption.ExternalTracker.ExternalTrackerURL = "htp://www.somewebsite.com"
req = NewRequestWithJSON(t, "PATCH", url, &repoEditOption)
Expand Down