Skip to content

Commit

Permalink
fix(api): disableStatusDetails flag
Browse files Browse the repository at this point in the history
Signed-off-by: Yvonnick Esnault <[email protected]>
  • Loading branch information
yesnault committed Aug 24, 2022
1 parent a4fa7d5 commit bd750e2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
10 changes: 6 additions & 4 deletions engine/api/repositoriesmanager/repositories_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (c *vcsClient) IsGerrit(ctx context.Context, db gorp.SqlExecutor) (bool, er
return vcsServer.Type == "gerrit", nil
}

//LoadAll Load all RepositoriesManager from the database
// LoadAll Load all RepositoriesManager from the database
func LoadAll(ctx context.Context, db *gorp.DbMap, store cache.Store) (map[string]sdk.VCSConfiguration, error) {
srvs, err := services.LoadAllByType(ctx, db, sdk.TypeVCS)
if err != nil {
Expand Down Expand Up @@ -191,7 +191,7 @@ func (c *vcsConsumer) GetAuthorizedClient(ctx context.Context, token, secret str
}, nil
}

//AuthorizedClient returns an implementation of AuthorizedClient wrapping calls to vcs uService
// AuthorizedClient returns an implementation of AuthorizedClient wrapping calls to vcs uService
func AuthorizedClient(ctx context.Context, db gorpmapper.SqlExecutorWithTx, store cache.Store, projectKey string, vcsName string) (sdk.VCSAuthorizedClientService, error) {
vcsProject, err := vcs.LoadVCSByProject(ctx, db, projectKey, vcsName, gorpmapping.GetOptions.WithDecryption)

Expand Down Expand Up @@ -627,9 +627,11 @@ func (c *vcsClient) SetStatus(ctx context.Context, event sdk.Event, disableStatu
return nil
}

// query param disableStatusDetails

path := fmt.Sprintf("/vcs/%s/status", c.name)
if disableStatusDetails {
path += "?disableStatusDetails=true"
}

_, err := c.doJSONRequest(ctx, "POST", path, event, nil)
return sdk.NewErrorFrom(err, "unable to set status on %s (workflow: %s, application: %s)", event.WorkflowName, event.ApplicationName, c.name)
}
Expand Down
8 changes: 5 additions & 3 deletions engine/vcs/github/client_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ func (client *githubClient) IsDisableStatusDetails(ctx context.Context) bool {
return client.DisableStatusDetails
}

//SetStatus Users with push access can create commit statuses for a given ref:
//https://developer.github.com/v3/repos/statuses/#create-a-status
// SetStatus Users with push access can create commit statuses for a given ref:
// https://developer.github.com/v3/repos/statuses/#create-a-status
func (g *githubClient) SetStatus(ctx context.Context, event sdk.Event, disableStatusDetails bool) error {
if g.DisableStatus {
log.Warn(ctx, "github.SetStatus> ⚠ Github statuses are disabled")
Expand All @@ -58,11 +58,13 @@ func (g *githubClient) SetStatus(ctx context.Context, event sdk.Event, disableSt

ghStatus := CreateStatus{
Description: data.desc,
TargetURL: data.urlPipeline,
State: data.status,
Context: data.context,
}

if !disableStatusDetails {
ghStatus.TargetURL = data.urlPipeline
}
path := fmt.Sprintf("/repos/%s/statuses/%s", data.repoFullName, data.hash)

b, err := json.Marshal(ghStatus)
Expand Down
2 changes: 1 addition & 1 deletion engine/vcs/vcs_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ func (s *Service) postStatusHandler() service.Handler {

var disableStatusDetails bool
d := r.URL.Query().Get("disableStatusDetails")
if d == "" {
if d != "" {
disableStatusDetails, _ = strconv.ParseBool(d)
} else {
disableStatusDetails = client.IsDisableStatusDetails(ctx)
Expand Down

0 comments on commit bd750e2

Please sign in to comment.