Skip to content

Commit 89a0bf7

Browse files
authored
Merge pull request #231 from whywaita/fix/230
Set installation object in rescue
2 parents f6512bd + dd1f24e commit 89a0bf7

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

pkg/gh/installation.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,22 @@ func _listAppsInstalledRepo(ctx context.Context, installationID int64) ([]*githu
102102
return repositories, nil
103103
}
104104

105+
// GetInstallationByID returns installation from cache by ID
106+
func GetInstallationByID(ctx context.Context, installationID int64) (*github.Installation, error) {
107+
installations, err := listInstallations(ctx)
108+
if err != nil {
109+
return nil, fmt.Errorf("failed to get installations: %w", err)
110+
}
111+
112+
for _, installation := range installations {
113+
if installation.GetID() == installationID {
114+
return installation, nil
115+
}
116+
}
117+
118+
return nil, fmt.Errorf("installation not found: %d", installationID)
119+
}
120+
105121
// PurgeInstallationCache purges the cache of installations
106122
func PurgeInstallationCache(ctx context.Context) error {
107123
installations, err := listInstallations(ctx)

pkg/starter/starter.go

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,13 +435,39 @@ func enqueueRescueRun(ctx context.Context, pendingRun datastore.PendingWorkflowR
435435
continue
436436
}
437437

438+
// Get installation ID from target scope
439+
installationID, err := gh.IsInstalledGitHubApp(ctx, target.Scope)
440+
if err != nil {
441+
return fmt.Errorf("failed to get installation ID: %w", err)
442+
}
443+
444+
// Get full installation data from cache
445+
installation, err := gh.GetInstallationByID(ctx, installationID)
446+
if err != nil {
447+
logger.Logf(false, "failed to get installation from cache (installationID: %d), using minimal data: %+v", installationID, err)
448+
// Fallback to minimal installation data
449+
installation = &github.Installation{
450+
ID: &installationID,
451+
}
452+
}
453+
454+
owner := pendingRun.WorkflowRun.GetRepository().GetOwner()
455+
var org *github.Organization
456+
if owner != nil {
457+
org = &github.Organization{
458+
ID: owner.ID,
459+
Login: owner.Login,
460+
Name: owner.Name,
461+
}
462+
}
463+
438464
event := &github.WorkflowJobEvent{
439465
WorkflowJob: job,
440466
Action: github.String("queued"),
441-
Org: nil,
467+
Org: org,
442468
Repo: pendingRun.WorkflowRun.GetRepository(),
443-
Sender: nil,
444-
Installation: nil,
469+
Sender: pendingRun.WorkflowRun.GetActor(),
470+
Installation: installation,
445471
}
446472

447473
if err := enqueueRescueJob(ctx, event, *target, ds); err != nil {

0 commit comments

Comments
 (0)