Enable Gitlab Error Tracking Settings API to toggle settings on new projects
Summary
Enable/Disable error tracking settings API, should work on new projects without intervention on UI.
Steps to reproduce
- Create a new project (via API or manually).
- Retrieve the project ID of the project created in the previous step. Let's assume it is
$PROJECT_ID
. - Use error tracking settings API to toggle settings on the the project.
The URL can look like this:
"https://gitlab.example.com/api/v4/projects/$PROJECT_ID/error_tracking/settings?active=true"
- The response would be a 404 instead of 200 with error message:
PATCH https://gitlab.com/api/v4/projects/${projectID}/error_tracking/settings: 404 {message: 404 Error Tracking Setting Not Found}
Example Project
- A sample program in Go that can reproduce this behavior.
package main
import (
"fmt"
gogitlab "github.com/xanzy/go-gitlab"
"log"
"net/http"
)
func main() {
glClient, err := gogitlab.NewClient(
"PRIVATE_TOKEN",
)
if err != nil {
log.Fatal("failed to create client:", err)
}
projectName := fmt.Sprintf("errortracking-test-%s", "random_identifier")
project, _, err := glClient.Projects.CreateProject(&gogitlab.CreateProjectOptions{Name: &projectName})
if err != nil {
log.Fatalln("error while creating project: ", err)
}
req, err := glClient.NewRequest(http.MethodPatch, fmt.Sprintf("projects/%d/error_tracking/settings", project.ID), nil, nil)
if err != nil {
log.Fatalln("failed to create req: ", err)
}
q := req.URL.Query()
q.Add("active", "true")
q.Add("integrated", "true")
req.URL.RawQuery = q.Encode()
resp, err := glClient.Do(req, nil)
if err != nil {
log.Fatalln("failed to enable error tracking: ", err)
}
if resp.StatusCode != http.StatusOK {
log.Fatalln("failed to enable error tracking: ", err)
}
}
What is the current bug behavior?
The API should allow to create and enable/disable the settings.
What is the expected correct behavior?
The API should either create or update the error tracking settings for the new project. In case of new projects, settings should be created.
A separate PUT
method can be provided with the same API.
Relevant logs and/or screenshots
Output of checks
Results of GitLab environment info
Expand for output related to GitLab environment info
(For installations with omnibus-gitlab package run and paste the output of: `sudo gitlab-rake gitlab:env:info`) (For installations from source run and paste the output of: `sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)
Results of GitLab application Check
Expand for output related to the GitLab application check
(For installations with omnibus-gitlab package run and paste the output of:
sudo gitlab-rake gitlab:check SANITIZE=true
)(For installations from source run and paste the output of:
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true
)(we will only investigate if the tests are passing)
Possible fixes
The API spec only allows a PATCH method.
It can modified to have a PUT
method as well.