@@ -92,7 +92,7 @@ func (gh *DiggerGithubClientMockProvider) Get(githubAppId int64, installationId
92
92
return ghClient , & token , nil
93
93
}
94
94
95
- func GetGithubService (gh GithubClientProvider , installationId int64 , repoFullName string , repoOwner string , repoName string ) (* github2. GithubService , * string , error ) {
95
+ func GetGithubClient (gh GithubClientProvider , installationId int64 , repoFullName string ) (* github. Client , * string , error ) {
96
96
installation , err := models .DB .GetGithubAppInstallationByIdAndRepo (installationId , repoFullName )
97
97
if err != nil {
98
98
log .Printf ("Error getting installation: %v" , err )
@@ -106,6 +106,10 @@ func GetGithubService(gh GithubClientProvider, installationId int64, repoFullNam
106
106
}
107
107
108
108
ghClient , token , err := gh .Get (installation .GithubAppId , installation .GithubInstallationId )
109
+ return ghClient , token , err
110
+ }
111
+ func GetGithubService (gh GithubClientProvider , installationId int64 , repoFullName string , repoOwner string , repoName string ) (* github2.GithubService , * string , error ) {
112
+ ghClient , token , err := GetGithubClient (gh , installationId , repoFullName )
109
113
if err != nil {
110
114
log .Printf ("Error creating github app client: %v" , err )
111
115
return nil , nil , fmt .Errorf ("Error creating github app client: %v" , err )
@@ -139,7 +143,7 @@ func SetPRStatusForJobs(prService *github2.GithubService, prNumber int, jobs []o
139
143
return nil
140
144
}
141
145
142
- func GetWorkflowIdAndUrlFromDiggerJobId (client * github.Client , repoOwner string , repoName string , job models. DiggerJob ) (int64 , string , error ) {
146
+ func GetWorkflowIdAndUrlFromDiggerJobId (client * github.Client , repoOwner string , repoName string , diggerJobID string ) (int64 , string , error ) {
143
147
timeFilter := time .Now ().Add (- 5 * time .Minute )
144
148
runs , _ , err := client .Actions .ListRepositoryWorkflowRuns (context .Background (), repoOwner , repoName , & github.ListWorkflowRunsOptions {
145
149
Created : ">= " + timeFilter .Format (time .RFC3339 ),
@@ -149,23 +153,24 @@ func GetWorkflowIdAndUrlFromDiggerJobId(client *github.Client, repoOwner string,
149
153
}
150
154
151
155
for _ , workflowRun := range runs .WorkflowRuns {
156
+ println (* workflowRun .ID )
152
157
workflowjobs , _ , err := client .Actions .ListWorkflowJobs (context .Background (), repoOwner , repoName , * workflowRun .ID , nil )
153
158
if err != nil {
154
159
return 0 , "#" , fmt .Errorf ("error listing workflow jobs for run %v %v" , workflowRun .ID , err )
155
160
}
156
161
157
162
for _ , workflowjob := range workflowjobs .Jobs {
158
163
for _ , step := range workflowjob .Steps {
159
- if strings .Contains (* step .Name , job . DiggerJobID ) {
164
+ if strings .Contains (* step .Name , diggerJobID ) {
160
165
return * workflowRun .ID , fmt .Sprintf ("https://github.com/%v/%v/actions/runs/%v" , repoOwner , repoName , * workflowRun .ID ), nil
161
166
}
162
167
}
163
168
164
169
}
165
170
}
166
-
167
171
return 0 , "#" , fmt .Errorf ("workflow not found" )
168
172
}
173
+
169
174
func TriggerGithubWorkflow (client * github.Client , repoOwner string , repoName string , job models.DiggerJob , jobString string , commentId int64 ) error {
170
175
log .Printf ("TriggerGithubWorkflow: repoOwner: %v, repoName: %v, commentId: %v" , repoOwner , repoName , commentId )
171
176
_ , err := client .Actions .CreateWorkflowDispatchEventByFileName (context .Background (), repoOwner , repoName , "digger_workflow.yml" , github.CreateWorkflowDispatchEventRequest {
0 commit comments