chore(ops/besadii): remove sourcegraph index update support

Change-Id: I4ee9a5a69c90e2050c60b2ef8483431d691b499f
Reviewed-on: https://cl.tvl.fyi/c/depot/+/12287
Tested-by: BuildkiteCI
Reviewed-by: flokli <flokli@flokli.de>
This commit is contained in:
Vincent Ambo 2024-08-23 14:14:53 +03:00 committed by tazjin
parent 11665f4e0a
commit caf653be32
2 changed files with 1 additions and 38 deletions

View file

@ -1,5 +1,5 @@
# This program is used as a Gerrit hook to trigger builds on # This program is used as a Gerrit hook to trigger builds on
# Buildkite, Sourcegraph reindexing and other maintenance tasks. # Buildkite and perform other maintenance tasks.
{ depot, ... }: { depot, ... }:
depot.nix.buildGo.program { depot.nix.buildGo.program {

View file

@ -8,7 +8,6 @@
// //
// Gerrit (ref-updated) hook: // Gerrit (ref-updated) hook:
// - Trigger Buildkite CI builds // - Trigger Buildkite CI builds
// - Trigger SourceGraph repository index updates
// //
// Buildkite (post-command) hook: // Buildkite (post-command) hook:
// - Submit CL verification status back to Gerrit // - Submit CL verification status back to Gerrit
@ -55,10 +54,6 @@ type config struct {
BuildkiteProject string `json:"buildkiteProject"` BuildkiteProject string `json:"buildkiteProject"`
BuildkiteToken string `json:"buildkiteToken"` BuildkiteToken string `json:"buildkiteToken"`
GerritChangeName string `json:"gerritChangeName"` GerritChangeName string `json:"gerritChangeName"`
// Optional configuration for Sourcegraph trigger updates.
SourcegraphUrl string `json:"sourcegraphUrl"`
SourcegraphToken string `json:"sourcegraphToken"`
} }
// buildTrigger represents the information passed to besadii when it // buildTrigger represents the information passed to besadii when it
@ -154,11 +149,6 @@ func loadConfig() (*config, error) {
return nil, fmt.Errorf("invalid 'gerritChangeName': %s", cfg.GerritChangeName) return nil, fmt.Errorf("invalid 'gerritChangeName': %s", cfg.GerritChangeName)
} }
// Rudimentary config validation logic
if cfg.SourcegraphUrl != "" && cfg.SourcegraphToken == "" {
return nil, fmt.Errorf("'SourcegraphToken' must be set if 'SourcegraphUrl' is set")
}
if cfg.Repository == "" || cfg.Branch == "" { if cfg.Repository == "" || cfg.Branch == "" {
return nil, fmt.Errorf("missing repository configuration (required: repository, branch)") return nil, fmt.Errorf("missing repository configuration (required: repository, branch)")
} }
@ -299,26 +289,6 @@ func triggerBuild(cfg *config, log *syslog.Writer, trigger *buildTrigger) error
return nil return nil
} }
// Trigger a Sourcegraph repository index update.
//
// https://docs.sourcegraph.com/admin/repo/webhooks
func triggerIndexUpdate(cfg *config, log *syslog.Writer) error {
req, err := http.NewRequest("POST", cfg.SourcegraphUrl, nil)
if err != nil {
return err
}
req.Header.Add("Authorization", "token "+cfg.SourcegraphToken)
_, err = http.DefaultClient.Do(req)
if err != nil {
return fmt.Errorf("failed to trigger Sourcegraph index update: %w", err)
}
log.Info("triggered sourcegraph index update")
return nil
}
// Gerrit passes more flags than we want, but Rob Pike decided[0] in // Gerrit passes more flags than we want, but Rob Pike decided[0] in
// 2013 that the Go art project will not allow users to ignore flags // 2013 that the Go art project will not allow users to ignore flags
// because he "doesn't like it". This function allows users to ignore // because he "doesn't like it". This function allows users to ignore
@ -458,13 +428,6 @@ func gerritHookMain(cfg *config, log *syslog.Writer, trigger *buildTrigger) {
if err != nil { if err != nil {
log.Err(fmt.Sprintf("failed to trigger Buildkite build: %s", err)) log.Err(fmt.Sprintf("failed to trigger Buildkite build: %s", err))
} }
if cfg.SourcegraphUrl != "" && trigger.ref == cfg.Branch {
err = triggerIndexUpdate(cfg, log)
if err != nil {
log.Err(fmt.Sprintf("failed to trigger sourcegraph index update: %s", err))
}
}
} }
func postCommandMain(cfg *config) { func postCommandMain(cfg *config) {