-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpatcher.go
68 lines (59 loc) · 1.86 KB
/
patcher.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package orchestrator
import (
"context"
"time"
artifact "github.com/deepcode-ai/artifacts/types"
)
const (
patcherPublishPath = "/api/runner/autofix/committer/results"
)
// PatcherTask represents the patcher job task structure.
type PatcherTask struct {
runner *Runner
driver Driver
provider Provider
signer Signer
opts *TaskOpts
}
// PatcherRunRequest represents the data corresponding to the patcher run including the
// AppID and InstallationID of the client.
type PatcherRunRequest struct {
Run *artifact.PatcherRun
AppID string
InstallationID string
}
// NewPatcherTask creates a new patching job task based on PatcherTask structure and returns it.
func NewPatcherTask(runner *Runner, opts *TaskOpts, driver Driver, provider Provider, signer Signer) *PatcherTask {
return &PatcherTask{
driver: driver,
provider: provider,
signer: signer,
opts: opts,
runner: runner,
}
}
// PatcherTask.Run creates a new patcher job based on the data passed to it
// and then triggers that job using the specified driver in the task.
func (p *PatcherTask) Run(ctx context.Context, req *PatcherRunRequest) error {
remoteURL, err := p.provider.AuthenticatedRemoteURL(req.AppID, req.InstallationID, req.Run.VCSMeta.RemoteURL)
if err != nil {
return err
}
token, err := p.signer.GenerateToken(p.runner.ID, []string{ScopeAutofix}, nil, 30*time.Minute)
if err != nil {
return err
}
req.Run.VCSMeta.RemoteURL = remoteURL
job, err := NewPatcherDriverJob(req.Run, &PatcherJobOpts{
PublisherURL: p.opts.RemoteHost + patcherPublishPath,
PublisherToken: token,
SnippetStorageType: p.opts.SnippetStorageType,
SnippetStorageBucket: p.opts.SnippetStorageBucket,
SentryDSN: p.opts.SentryDSN,
KubernetesOpts: p.opts.KubernetesOpts,
})
if err != nil {
return err
}
return p.driver.TriggerJob(ctx, job)
}