Skip to content

Commit 5a5aafd

Browse files
authored
Merge pull request #112 from dwasinge/hook-fix
BugFix: No Webhooks added to New Engagements
2 parents 7e7d6b3 + bf4f68d commit 5a5aafd

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/main/java/com/redhat/labs/lodestar/service/ConfigService.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public class ConfigService {
7777
*/
7878
@Scheduled(every = "30s")
7979
void reloadConfigMapData() {
80-
if(reloadConfig) {
80+
if (reloadConfig) {
8181
loadWebHookData();
8282
loadConfigurationData();
8383
}
@@ -181,6 +181,23 @@ boolean engagementIsArchived(Project project) {
181181

182182
}
183183

184+
/**
185+
* Adds all configured webhooks to the project for the given {@link Engagement}.
186+
*
187+
* @param engagement
188+
*
189+
*/
190+
public void createWebhooksForEnagement(Engagement engagement) {
191+
192+
List<HookConfig> hookConfigs = getHookConfig();
193+
hookConfigs.stream().forEach(hookC -> {
194+
Hook hook = Hook.builder().projectId(engagement.getProjectId()).pushEvents(true).url(hookC.getBaseUrl())
195+
.token(hookC.getToken()).build();
196+
hookService.createProjectHook(engagement.getProjectId(), hook);
197+
});
198+
199+
}
200+
184201
/**
185202
* Loads the configuration data from the configured file if it has been
186203
* modified.

src/main/java/com/redhat/labs/lodestar/service/EngagementService.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ public class EngagementService {
6767
@Inject
6868
HookService hookService;
6969

70+
@Inject
71+
ConfigService configService;
72+
7073
@Inject
7174
ProjectStructureService structureService;
7275

@@ -115,6 +118,11 @@ public Project createEngagement(Engagement engagement, String author, String aut
115118
throw new UnexpectedGitLabResponseException("failed to commit files for engagement creation.");
116119
}
117120

121+
// create hooks if new engagement, should already exist if updating
122+
if(project.isFirst()) {
123+
configService.createWebhooksForEnagement(engagement);
124+
}
125+
118126
return project;
119127

120128
}

0 commit comments

Comments
 (0)