Make external issue tracker regexp configurable via API (#21338)
Fixes #21336 Signed-off-by: Andrew Imeson <andrew@andrewimeson.com>
This commit is contained in:
parent
81d7270cde
commit
d94f15c2fd
5 changed files with 32 additions and 11 deletions
|
@ -56,9 +56,10 @@ func innerToRepo(repo *repo_model.Repository, mode perm.AccessMode, isParent boo
|
||||||
config := unit.ExternalTrackerConfig()
|
config := unit.ExternalTrackerConfig()
|
||||||
hasIssues = true
|
hasIssues = true
|
||||||
externalTracker = &api.ExternalTracker{
|
externalTracker = &api.ExternalTracker{
|
||||||
ExternalTrackerURL: config.ExternalTrackerURL,
|
ExternalTrackerURL: config.ExternalTrackerURL,
|
||||||
ExternalTrackerFormat: config.ExternalTrackerFormat,
|
ExternalTrackerFormat: config.ExternalTrackerFormat,
|
||||||
ExternalTrackerStyle: config.ExternalTrackerStyle,
|
ExternalTrackerStyle: config.ExternalTrackerStyle,
|
||||||
|
ExternalTrackerRegexpPattern: config.ExternalTrackerRegexpPattern,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hasWiki := false
|
hasWiki := false
|
||||||
|
|
|
@ -34,8 +34,10 @@ type ExternalTracker struct {
|
||||||
ExternalTrackerURL string `json:"external_tracker_url"`
|
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.
|
// 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"`
|
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"`
|
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
|
// ExternalWiki represents setting for external wiki
|
||||||
|
|
|
@ -755,9 +755,10 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
|
||||||
RepoID: repo.ID,
|
RepoID: repo.ID,
|
||||||
Type: unit_model.TypeExternalTracker,
|
Type: unit_model.TypeExternalTracker,
|
||||||
Config: &repo_model.ExternalTrackerConfig{
|
Config: &repo_model.ExternalTrackerConfig{
|
||||||
ExternalTrackerURL: opts.ExternalTracker.ExternalTrackerURL,
|
ExternalTrackerURL: opts.ExternalTracker.ExternalTrackerURL,
|
||||||
ExternalTrackerFormat: opts.ExternalTracker.ExternalTrackerFormat,
|
ExternalTrackerFormat: opts.ExternalTracker.ExternalTrackerFormat,
|
||||||
ExternalTrackerStyle: opts.ExternalTracker.ExternalTrackerStyle,
|
ExternalTrackerStyle: opts.ExternalTracker.ExternalTrackerStyle,
|
||||||
|
ExternalTrackerRegexpPattern: opts.ExternalTracker.ExternalTrackerRegexpPattern,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeIssues)
|
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeIssues)
|
||||||
|
|
|
@ -16015,8 +16015,13 @@
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"x-go-name": "ExternalTrackerFormat"
|
"x-go-name": "ExternalTrackerFormat"
|
||||||
},
|
},
|
||||||
|
"external_tracker_regexp_pattern": {
|
||||||
|
"description": "External Issue Tracker issue regular expression",
|
||||||
|
"type": "string",
|
||||||
|
"x-go-name": "ExternalTrackerRegexpPattern"
|
||||||
|
},
|
||||||
"external_tracker_style": {
|
"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",
|
"type": "string",
|
||||||
"x-go-name": "ExternalTrackerStyle"
|
"x-go-name": "ExternalTrackerStyle"
|
||||||
},
|
},
|
||||||
|
|
|
@ -40,9 +40,10 @@ func getRepoEditOptionFromRepo(repo *repo_model.Repository) *api.EditRepoOption
|
||||||
config := unit.ExternalTrackerConfig()
|
config := unit.ExternalTrackerConfig()
|
||||||
hasIssues = true
|
hasIssues = true
|
||||||
externalTracker = &api.ExternalTracker{
|
externalTracker = &api.ExternalTracker{
|
||||||
ExternalTrackerURL: config.ExternalTrackerURL,
|
ExternalTrackerURL: config.ExternalTrackerURL,
|
||||||
ExternalTrackerFormat: config.ExternalTrackerFormat,
|
ExternalTrackerFormat: config.ExternalTrackerFormat,
|
||||||
ExternalTrackerStyle: config.ExternalTrackerStyle,
|
ExternalTrackerStyle: config.ExternalTrackerStyle,
|
||||||
|
ExternalTrackerRegexpPattern: config.ExternalTrackerRegexpPattern,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hasWiki := false
|
hasWiki := false
|
||||||
|
@ -220,6 +221,17 @@ func TestAPIRepoEdit(t *testing.T) {
|
||||||
assert.Equal(t, *repo1editedOption.HasWiki, true)
|
assert.Equal(t, *repo1editedOption.HasWiki, true)
|
||||||
assert.Equal(t, *repo1editedOption.ExternalWiki, *repoEditOption.ExternalWiki)
|
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
|
// Do some tests with invalid URL for external tracker and wiki
|
||||||
repoEditOption.ExternalTracker.ExternalTrackerURL = "htp://www.somewebsite.com"
|
repoEditOption.ExternalTracker.ExternalTrackerURL = "htp://www.somewebsite.com"
|
||||||
req = NewRequestWithJSON(t, "PATCH", url, &repoEditOption)
|
req = NewRequestWithJSON(t, "PATCH", url, &repoEditOption)
|
||||||
|
|
Loading…
Add table
Reference in a new issue