Dusan Hornik avatar Dusan Hornik committed 8ce5b57

BBC-65 Creating post commit hook when new repository is added

Comments (0)

Files changed (3)

src/main/java/com/atlassian/jira/plugins/bitbucket/spi/RepositoryManager.java

 
 public interface RepositoryManager
 {
-	
-	/**
-	 * Returns true if this RepositoryManager can manage repository with given url
-	 * @param url
-	 * @return
-	 */
-	public boolean canHandleUrl(String url);
-	
-	/**
-	 * Mapps a repository to given project
-	 *
-	 * @param projectKey
-	 * @param repositoryUrl
-	 * @param username
-	 * @param password
-	 * @param adminUsername - used when (un)installing postcommit hook
-	 * @param adminPassword - used when (un)installing postcommit hook
-	 * @return
-	 */
-	public SourceControlRepository addRepository(String projectKey, String repositoryUrl, String username, String password, String adminUsername, String adminPassword);
-	
-	/**
-	 * @param repositoryId
-	 * @return repository with given id
-	 * throws IllegalArgumentException if repository with given id is not found
-	 */
-	public SourceControlRepository getRepository(int repositoryId);
-	
-	/**
-	 * @param projectKey
-	 * @return list of repositories linked with given project
-	 */
-	public List<SourceControlRepository> getRepositories(String projectKey);
 
-	/**
-	 * @param issueKey
-	 * @return list of changesets linked to the given issue
-	 */
-	public List<Changeset> getChangesets(String issueKey);
+    /**
+     * Returns true if this RepositoryManager can manage repository with given url
+     * @param url
+     * @return
+     */
+    public boolean canHandleUrl(String url);
 
-	/**
-	 * Removes the repository with given id and all the issue mappings for this repository
-	 * @param id
-	 */
-	public void removeRepository(int id);
+    /**
+     * Mapps a repository to given project
+     *
+     * @param projectKey
+     * @param repositoryUrl
+     * @param username
+     * @param password
+     * @param adminUsername - used when (un)installing postcommit hook
+     * @param adminPassword - used when (un)installing postcommit hook
+     * @return
+     */
+    public SourceControlRepository addRepository(String projectKey, String repositoryUrl, String username,
+            String password, String adminUsername, String adminPassword);
 
-	/**
-	 * Links changeset with given issue
-	 * @param sourceControlRepository
-	 * @param issueId
-	 * @param changeset
-	 */
-	public void addChangeset(SourceControlRepository sourceControlRepository, String issueId, Changeset changeset);
+    /**
+     * @param repositoryId
+     * @return repository with given id
+     * throws IllegalArgumentException if repository with given id is not found
+     */
+    public SourceControlRepository getRepository(int repositoryId);
 
-	/**
-	 * @param repositoryUrl
-	 * @param username
-	 * @return the details about the user
-	 */
-	public SourceControlUser getUser(SourceControlRepository repository, String username);
+    /**
+     * @param projectKey
+     * @return list of repositories linked with given project
+     */
+    public List<SourceControlRepository> getRepositories(String projectKey);
 
-	/**
-	 * Returns callback function that is used for synchronisation of the repository. 
-	 * @param key
-	 * @param progress 
-	 * @return
-	 */
-	public SynchronisationOperation getSynchronisationOperation(SynchronizationKey key, ProgressWriter progress);
+    /**
+     * @param issueKey
+     * @return list of changesets linked to the given issue
+     */
+    public List<Changeset> getChangesets(String issueKey);
 
-	/**
-	 * Parses the given json string into changesets
-	 * @param repository
-	 * @param payload
-	 * @return
-	 */
-	public List<Changeset> parsePayload(SourceControlRepository repository, String payload);
+    /**
+     * Removes the repository with given id and all the issue mappings for this repository
+     * @param id
+     */
+    public void removeRepository(int id);
 
-	/**
-	 * @param repository
-	 * @param changeset
-	 * @return the html used for rendering this changeset on the issue.
-	 */
-	public String getHtmlForChangeset(SourceControlRepository repository, Changeset changeset);
+    /**
+     * Links changeset with given issue
+     * @param sourceControlRepository
+     * @param issueId
+     * @param changeset
+     */
+    public void addChangeset(SourceControlRepository sourceControlRepository, String issueId, Changeset changeset);
 
-	/**
-	 * Installs a postcommit service for this repository
-	 * @param repo
-	 */
-	public void setupPostcommitHook(SourceControlRepository repo);
-	
-	/**
-	 * Removes a postcommit service for this repository
-	 * @param repo
-	 */
-	public void removePostcommitHook(SourceControlRepository repo);
+    /**
+     * @param repositoryUrl
+     * @param username
+     * @return the details about the user
+     */
+    public SourceControlUser getUser(SourceControlRepository repository, String username);
 
-	/**
+    /**
+     * Returns callback function that is used for synchronisation of the repository. 
+     * @param key
+     * @param progress 
+     * @return
+     */
+    public SynchronisationOperation getSynchronisationOperation(SynchronizationKey key, ProgressWriter progress);
+
+    /**
+     * Parses the given json string into changesets
+     * @param repository
+     * @param payload
+     * @return
+     */
+    public List<Changeset> parsePayload(SourceControlRepository repository, String payload);
+
+    /**
+     * @param repository
+     * @param changeset
+     * @return the html used for rendering this changeset on the issue.
+     */
+    public String getHtmlForChangeset(SourceControlRepository repository, Changeset changeset);
+
+    /**
+     * Installs a postcommit service for this repository
+     * @param repo
+     */
+    public void setupPostcommitHook(SourceControlRepository repo);
+
+    /**
+     * Removes a postcommit service for this repository
+     * @param repo
+     */
+    public void removePostcommitHook(SourceControlRepository repo);
+
+    /**
      *
      * @return the identifier of repository type
      */
-   public String getRepositoryTypeId();
+    public String getRepositoryTypeId();
 
 }

src/main/java/com/atlassian/jira/plugins/bitbucket/webwork/ConfigureBitbucketRepositories.java

 import com.atlassian.jira.project.Project;
 import com.atlassian.jira.security.xsrf.RequiresXsrfCheck;
 import com.atlassian.jira.web.action.JiraWebActionSupport;
+import com.atlassian.sal.api.ApplicationProperties;
 
 /**
  * Webwork action used to configure the bitbucket repositories
     private final String redirectURL = "";
     private String addPostCommitService = "";
     private int repositoryId;
+    private final String baseUrl;
 
     private final RepositoryManager globalRepositoryManager;
 
     public ConfigureBitbucketRepositories(
-            @Qualifier("globalRepositoryManager") RepositoryManager globalRepositoryManager)
+            @Qualifier("globalRepositoryManager") RepositoryManager globalRepositoryManager,
+            ApplicationProperties applicationProperties)
     {
         this.globalRepositoryManager = globalRepositoryManager;
+        this.baseUrl = applicationProperties.getBaseUrl();
     }
 
     @Override
                         globalRepositoryManager.setupPostcommitHook(repo);
                     }
                     repositoryId = repo.getId();
-                    postCommitURL = "BitbucketPostCommit.jspa?repositoryId=" + repositoryId;
+                    postCommitURL = baseUrl + "/rest/bitbucket/1.0/repository/" + repositoryId + "/sync";
                     nextAction = "ForceSync";
                 }
             }

src/main/resources/templates/com/atlassian/jira/plugins/bitbucket/webwork/input.vm

 
                 #if ($action.getPostCommitURL() != "")
                     <div>
-                           <h3 id="gh_post_receive_header">Add a Post-Commit Hook</h3>
-
+                           <h3 id="gh_post_receive_header">Post-Commit Hook</h3>
                             <p>Please add the URL below as a post-commit service to the Bitbucket repository.</p>
-
                             <p>
-								<input id="gh_post_receive_textbox" type"text" size="90" value="${baseurl}/$action.getPostCommitURL()">
+								<input id="gh_post_receive_textbox" type"text" size="90" value="$action.getPostCommitURL()">
                             </p>
 
                     </div>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.