-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for associating WebHook templates with Projects
This allows a WebHook Template to be created and associated with a project rather then just _Root. Now group admins can create templates for use with their own webhooks. This addresses issue #131 Note: WebHook Template Ids must be unique across a teamcity instance, even if the user creating the template is not aware and is not permissioned to see an existing template with that ID. - Uses templateId rather than templateName when referring to ID. - Added projectId field and getProjectId method to templates. - Added validators and permissions - Fixed up permissions for template editing in REST API - Added Templates to WebHook Project tab - Added Templates list to Webhook Project Config tab. - Added Project Name and link to Templates page. - WebHooks now resolve project specific templates when building payload.
- Loading branch information
Showing
93 changed files
with
4,116 additions
and
2,860 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package webhook; | ||
|
||
public class Constants { | ||
|
||
private Constants() {} | ||
|
||
public static final String ROOT_PROJECT_ID = "_Root"; | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
tcwebhooks-core/src/main/java/webhook/teamcity/DeferrableService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package webhook.teamcity; | ||
|
||
public interface DeferrableService { | ||
|
||
/** | ||
* Register with the deferred startup service. | ||
* Later it will invoke the deferredStart method. | ||
*/ | ||
public void requestDeferredRegistration(); | ||
|
||
/** | ||
* Run any initialisation code after TeamCity has started. | ||
*/ | ||
public void register(); | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
tcwebhooks-core/src/main/java/webhook/teamcity/DeferrableServiceManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package webhook.teamcity; | ||
|
||
public interface DeferrableServiceManager { | ||
|
||
public void registerService(DeferrableService deferrableService); | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
tcwebhooks-core/src/main/java/webhook/teamcity/DeferrableServiceManagerImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package webhook.teamcity; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import jetbrains.buildServer.serverSide.BuildServerAdapter; | ||
import jetbrains.buildServer.serverSide.SBuildServer; | ||
|
||
public class DeferrableServiceManagerImpl implements DeferrableServiceManager { | ||
|
||
List<DeferrableService> deferrableServices = new ArrayList<>(); | ||
|
||
public DeferrableServiceManagerImpl(SBuildServer server) { | ||
server.addListener(new BuildServerAdapter() { | ||
@Override | ||
public void serverStartup() { | ||
deferrableServices.forEach(DeferrableService::register); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void registerService(DeferrableService deferrableService) { | ||
deferrableServices.add(deferrableService); | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
tcwebhooks-core/src/main/java/webhook/teamcity/ProjectIdResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package webhook.teamcity; | ||
|
||
public interface ProjectIdResolver { | ||
|
||
String getExternalProjectId(String internalProjectId); | ||
String getInternalProjectId(String externalProjectId); | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
tcwebhooks-core/src/main/java/webhook/teamcity/ProjectIdResolverImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package webhook.teamcity; | ||
|
||
import java.util.Objects; | ||
|
||
import jetbrains.buildServer.serverSide.ProjectManager; | ||
import webhook.teamcity.exception.NonExistantProjectException; | ||
|
||
public class ProjectIdResolverImpl implements ProjectIdResolver { | ||
|
||
private ProjectManager myProjectManager; | ||
|
||
public ProjectIdResolverImpl(ProjectManager projectManager) { | ||
myProjectManager = projectManager; | ||
} | ||
|
||
@Override | ||
public String getExternalProjectId(String internalProjectId) { | ||
try { | ||
if (Objects.isNull(internalProjectId) || internalProjectId.isEmpty()) { | ||
return(myProjectManager.findProjectById("_Root").getExternalId()); | ||
} | ||
return myProjectManager.findProjectById(internalProjectId).getExternalId(); | ||
} catch (NullPointerException e) { | ||
throw new NonExistantProjectException("No project found with matching internal Id:" + internalProjectId, internalProjectId); | ||
} | ||
} | ||
|
||
@Override | ||
public String getInternalProjectId(String externalProjectId) { | ||
try { | ||
if (Objects.isNull(externalProjectId) || externalProjectId.isEmpty()) { | ||
return(myProjectManager.findProjectByExternalId("_Root").getProjectId()); | ||
} | ||
return myProjectManager.findProjectByExternalId(externalProjectId).getProjectId(); | ||
} catch (NullPointerException npe) { | ||
throw new NonExistantProjectException("No project found with matching external Id:" + externalProjectId, externalProjectId); | ||
} | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
tcwebhooks-core/src/main/java/webhook/teamcity/exception/NonExistantProjectException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package webhook.teamcity.exception; | ||
|
||
import lombok.Getter; | ||
|
||
public class NonExistantProjectException extends RuntimeException { | ||
private static final long serialVersionUID = 1L; | ||
|
||
@Getter | ||
private final String projectID; | ||
|
||
public NonExistantProjectException(String message, String projectId) { | ||
super(message); | ||
this.projectID = projectId; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.