Refactor pipeline parsing and forge refreshing (#2527)

- refactor pipeline parsing
- do not parse the pipeline multiple times to perform filter checks, do
this once and perform checks on the result directly
    - code deduplication
- refactor forge token refreshing
    - move refreshing to a helper func to reduce code

---------

Co-authored-by: Anbraten <anton@ju60.de>
This commit is contained in:
qwerty287
2023-10-08 14:05:06 +02:00
committed by GitHub
parent 2f4690a6b6
commit 22dfd2ef62
23 changed files with 251 additions and 392 deletions

View File

@@ -121,22 +121,10 @@ func CreatePipeline(ctx context.Context, store store.Store, f forge.Forge, cron
return nil, nil, err
}
// if the forge has a refresh token, the current access token
// If the forge has a refresh token, the current access token
// may be stale. Therefore, we should refresh prior to dispatching
// the pipeline.
if refresher, ok := f.(forge.Refresher); ok {
refreshed, err := refresher.Refresh(ctx, creator)
if err != nil {
log.Error().Err(err).Msgf("failed to refresh oauth2 token for creator: %s", creator.Login)
} else if refreshed {
if err := store.UpdateUser(creator); err != nil {
log.Error().Err(err).Msgf("error while updating creator: %s", creator.Login)
// move forward
} else {
log.Debug().Msgf("token refreshed for creator: %s", creator.Login)
}
}
}
forge.Refresh(ctx, f, store, creator)
commit, err := f.BranchHead(ctx, creator, repo, cron.Branch)
if err != nil {