Skip to content

Commit fcba553

Browse files
committed
Support repository deletion.
Use QuickReload instead of FastDev.
1 parent d638906 commit fcba553

File tree

3 files changed

+51
-8
lines changed

3 files changed

+51
-8
lines changed

pom.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,21 @@
161161
<dataVersion>${stash.data.version}</dataVersion>
162162
</product>
163163
</products>
164+
<enableFastdev>false</enableFastdev>
165+
<enableDevToolbox>false</enableDevToolbox>
166+
<enablePde>false</enablePde>
167+
<skipRestDocGeneration>true</skipRestDocGeneration>
168+
<allowGoogleTracking>false</allowGoogleTracking>
169+
<skipManifestValidation>true</skipManifestValidation>
170+
<extractDependencies>false</extractDependencies>
171+
<skipManifestValidation>true</skipManifestValidation>
172+
<pluginArtifact>
173+
<groupId>com.atlassian.labs.plugins</groupId>
174+
<artifactId>quickreload</artifactId>
175+
<version>${quick.reload.version}</version>
176+
</pluginArtifact>
177+
<enableQuickReload>true</enableQuickReload>
178+
<quickReloadVersion>${quick.reload.version}</quickReloadVersion>
164179
</configuration>
165180
</plugin>
166181
<plugin>
@@ -191,5 +206,6 @@
191206
<amps.version>5.1.11</amps.version>
192207
<ao.version>0.28.1</ao.version>
193208
<plugin.testrunner.version>1.1.4</plugin.testrunner.version>
209+
<quick.reload.version>1.29</quick.reload.version>
194210
</properties>
195211
</project>

src/main/java/com/github/wadahiro/bitbucket/branchauthor/BranchAuthorImpl.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,12 @@ public static void deleteBranchAuthor(ActiveObjects ao, Integer repoId, String b
5353
ao.delete(branchAuthors[0]);
5454
}
5555
}
56+
57+
public static void deleteAllBranchAuthor(ActiveObjects ao, Integer repoId) throws SQLException {
58+
BranchAuthor[] branchAuthors = ao.find(BranchAuthor.class, Query.select().where("REPO_ID = ?", repoId));
59+
60+
for (BranchAuthor branchAuthor : branchAuthors) {
61+
ao.delete(branchAuthor);
62+
}
63+
}
5664
}

src/main/java/com/github/wadahiro/bitbucket/branchauthor/BranchListener.java

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.atlassian.activeobjects.external.ActiveObjects;
1111
import com.atlassian.event.api.EventListener;
1212
import com.atlassian.stash.event.AbstractRepositoryRefsChangedEvent;
13+
import com.atlassian.stash.event.RepositoryDeletedEvent;
1314
import com.atlassian.stash.repository.RefChange;
1415
import com.atlassian.stash.repository.RefChangeType;
1516
import com.atlassian.stash.repository.Repository;
@@ -29,16 +30,15 @@ public BranchListener(ActiveObjects activeObjects) {
2930
}
3031

3132
/**
32-
* We must use AbstractRepositoryRefsChangedEvent for handling all ADD/DELETE branch events.
33-
* See https://jira.atlassian.com/browse/BSERV-4269.
33+
* We must use AbstractRepositoryRefsChangedEvent for handling all
34+
* ADD/DELETE branch events.
35+
* See https://jira.atlassian.com/browse/BSERV-4269.
3436
* Using AbstractRepositoryRefsChangedEvent, we can support following operations.
3537
*
36-
* Branch creation from GUI
37-
* Branch deletion from GUI
38-
* Branch creation from Git client (git push origin <branch_name>)
39-
* Branch deletion from Git client (git push --delete origin <branch_name>)
40-
* Branch deletion by merged pull request(use source branch deletion)
41-
* Branch creation by fork syncing
38+
* Branch creation from GUI Branch deletion from GUI Branch creation from
39+
* Git client (git push origin <branch_name>) Branch deletion from Git
40+
* client (git push --delete origin <branch_name>) Branch deletion by merged
41+
* pull request(use source branch deletion) Branch creation by fork syncing
4242
* Branch deletion by fork syncing
4343
*
4444
* @param event
@@ -79,6 +79,17 @@ public void onRefsChanged(AbstractRepositoryRefsChangedEvent event) {
7979
}
8080
}
8181

82+
@EventListener
83+
public void onRepositoryDeleted(RepositoryDeletedEvent event) {
84+
Repository repo = event.getRepository();
85+
86+
Integer repoId = repo.getId();
87+
88+
log.info("RepositoryDeletedEvent: Delete all branch authors in a repo. repoId={}", repoId);
89+
90+
deleteAllBranchAuthor(repoId);
91+
}
92+
8293
private void createBranchAuthor(Integer repoId, Date created, String branchRef, Integer userId, String userEmail) {
8394
try {
8495
BranchAuthorImpl.saveBranchAuthor(activeObjects, repoId, created, branchRef, userId, userEmail);
@@ -94,4 +105,12 @@ private void deleteBranchAuthor(Integer repoId, String branchRef) {
94105
log.error("Deleting branch author error. repoid={}, branchRef={}", repoId, branchRef, e);
95106
}
96107
}
108+
109+
private void deleteAllBranchAuthor(Integer repoId) {
110+
try {
111+
BranchAuthorImpl.deleteAllBranchAuthor(activeObjects, repoId);
112+
} catch (SQLException e) {
113+
log.error("Deleting branch authors error. repoid={}", repoId, e);
114+
}
115+
}
97116
}

0 commit comments

Comments
 (0)