mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-24 10:07:21 +02:00
Merge branch 'main' into nix_add_build-target
This commit is contained in:
commit
3904e56c99
@ -287,7 +287,7 @@ var flags = append([]cli.Flag{
|
||||
Sources: cli.EnvVars("WOODPECKER_FORGE_TIMEOUT"),
|
||||
Name: "forge-timeout",
|
||||
Usage: "how many seconds before timeout when fetching the Woodpecker configuration from a Forge",
|
||||
Value: time.Second * 3,
|
||||
Value: time.Second * 5,
|
||||
},
|
||||
&cli.UintFlag{
|
||||
Sources: cli.EnvVars("WOODPECKER_FORGE_RETRY"),
|
||||
|
@ -484,7 +484,7 @@ Specify a configuration service endpoint, see [Configuration Extension](./40-adv
|
||||
|
||||
### `WOODPECKER_FORGE_TIMEOUT`
|
||||
|
||||
> Default: 3s
|
||||
> Default: 5s
|
||||
|
||||
Specify timeout when fetching the Woodpecker configuration from forge. See <https://pkg.go.dev/time#ParseDuration> for syntax reference.
|
||||
|
||||
|
@ -44,8 +44,9 @@ func ParamsToEnv(from map[string]any, to map[string]string, prefix string, upper
|
||||
|
||||
// sanitizeParamKey formats the environment variable key.
|
||||
func sanitizeParamKey(prefix string, upper bool, k string) string {
|
||||
r := strings.ReplaceAll(strings.ReplaceAll(k, ".", "_"), "-", "_")
|
||||
r := k
|
||||
if upper {
|
||||
r = strings.ReplaceAll(strings.ReplaceAll(k, ".", "_"), "-", "_")
|
||||
r = strings.ToUpper(r)
|
||||
}
|
||||
return prefix + r
|
||||
|
@ -110,8 +110,9 @@ func TestSanitizeParamKey(t *testing.T) {
|
||||
assert.EqualValues(t, "PLUGIN_DRY_RUN", sanitizeParamKey("PLUGIN_", true, "dry-run"))
|
||||
assert.EqualValues(t, "PLUGIN_DRY_RUN", sanitizeParamKey("PLUGIN_", true, "dry_Run"))
|
||||
assert.EqualValues(t, "PLUGIN_DRY_RUN", sanitizeParamKey("PLUGIN_", true, "dry.run"))
|
||||
assert.EqualValues(t, "PLUGIN_dry_run", sanitizeParamKey("PLUGIN_", false, "dry-run"))
|
||||
assert.EqualValues(t, "PLUGIN_dry-run", sanitizeParamKey("PLUGIN_", false, "dry-run"))
|
||||
assert.EqualValues(t, "PLUGIN_dry_Run", sanitizeParamKey("PLUGIN_", false, "dry_Run"))
|
||||
assert.EqualValues(t, "PLUGIN_dry.run", sanitizeParamKey("PLUGIN_", false, "dry.run"))
|
||||
}
|
||||
|
||||
func TestYAMLToParamsToEnv(t *testing.T) {
|
||||
|
@ -541,7 +541,6 @@ func (g *GitLab) Deactivate(ctx context.Context, user *model.User, repo *model.R
|
||||
return err
|
||||
}
|
||||
|
||||
hookID := -1
|
||||
listProjectHooksOptions := &gitlab.ListProjectHooksOptions{
|
||||
PerPage: perPage,
|
||||
Page: 1,
|
||||
@ -553,13 +552,15 @@ func (g *GitLab) Deactivate(ctx context.Context, user *model.User, repo *model.R
|
||||
}
|
||||
|
||||
for _, hook := range hooks {
|
||||
if hook.URL == webURL {
|
||||
hookID = hook.ID
|
||||
break
|
||||
if strings.Contains(hook.URL, webURL) {
|
||||
_, err = client.Projects.DeleteProjectHook(_repo.ID, hook.ID, gitlab.WithContext(ctx))
|
||||
log.Info().Msg(fmt.Sprintf("successfully deleted hook with ID %d for repo %s", hook.ID, repo.FullName))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Exit the loop when we've seen all pages
|
||||
if resp.CurrentPage >= resp.TotalPages {
|
||||
break
|
||||
}
|
||||
@ -568,13 +569,7 @@ func (g *GitLab) Deactivate(ctx context.Context, user *model.User, repo *model.R
|
||||
listProjectHooksOptions.Page = resp.NextPage
|
||||
}
|
||||
|
||||
if hookID == -1 {
|
||||
return fmt.Errorf("could not find hook to delete")
|
||||
}
|
||||
|
||||
_, err = client.Projects.DeleteProjectHook(_repo.ID, hookID, gitlab.WithContext(ctx))
|
||||
|
||||
return err
|
||||
return nil
|
||||
}
|
||||
|
||||
// Branches returns the names of all branches for the named repository.
|
||||
|
@ -59,10 +59,9 @@ func (f *forgeFetcher) Fetch(ctx context.Context, forge forge.Forge, user *model
|
||||
for i := 0; i < int(f.retryCount); i++ {
|
||||
files, err = ffc.fetch(ctx, strings.TrimSpace(repo.Config))
|
||||
if err != nil {
|
||||
log.Trace().Err(err).Msgf("%d. try failed", i+1)
|
||||
}
|
||||
if errors.Is(err, context.DeadlineExceeded) {
|
||||
continue
|
||||
log.Trace().Err(err).Msgf("Fetching config files: Attempt #%d failed", i+1)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,11 +142,12 @@ func (f *forgeFetcherContext) getFirstAvailableConfig(c context.Context, configs
|
||||
for _, fileOrFolder := range configs {
|
||||
if strings.HasSuffix(fileOrFolder, "/") {
|
||||
// config is a folder
|
||||
log.Trace().Msgf("fetching %s from forge", fileOrFolder)
|
||||
files, err := f.forge.Dir(c, f.user, f.repo, f.pipeline, strings.TrimSuffix(fileOrFolder, "/"))
|
||||
// if folder is not supported we will get a "Not implemented" error and continue
|
||||
if err != nil {
|
||||
if !(errors.Is(err, types.ErrNotImplemented) || errors.Is(err, &types.ErrConfigNotFound{})) {
|
||||
log.Error().Err(err).Str("repo", f.repo.FullName).Str("user", f.user.Login).Msg("could not get folder from forge")
|
||||
log.Error().Err(err).Str("repo", f.repo.FullName).Str("user", f.user.Login).Msgf("could not get folder from forge: %s", err)
|
||||
forgeErr = append(forgeErr, err)
|
||||
}
|
||||
continue
|
||||
|
@ -287,7 +287,7 @@ func TestFetch(t *testing.T) {
|
||||
f := new(mocks.Forge)
|
||||
dirs := map[string][]*forge_types.FileMeta{}
|
||||
for _, file := range tt.files {
|
||||
f.On("File", mock.Anything, mock.Anything, mock.Anything, mock.Anything, file.name).Return(file.data, nil)
|
||||
f.On("File", mock.Anything, mock.Anything, mock.Anything, mock.Anything, file.name).Once().Return(file.data, nil)
|
||||
path := filepath.Dir(file.name)
|
||||
if path != "." {
|
||||
dirs[path] = append(dirs[path], &forge_types.FileMeta{
|
||||
@ -298,7 +298,7 @@ func TestFetch(t *testing.T) {
|
||||
}
|
||||
|
||||
for path, files := range dirs {
|
||||
f.On("Dir", mock.Anything, mock.Anything, mock.Anything, mock.Anything, path).Return(files, nil)
|
||||
f.On("Dir", mock.Anything, mock.Anything, mock.Anything, mock.Anything, path).Once().Return(files, nil)
|
||||
}
|
||||
|
||||
// if the previous mocks do not match return not found errors
|
||||
|
Loading…
Reference in New Issue
Block a user