Skip to content

Commit 12115eb

Browse files
committed
Support repository deletion.
1 parent d265e2d commit 12115eb

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import com.atlassian.activeobjects.external.ActiveObjects;
1111
import com.atlassian.bitbucket.event.repository.AbstractRepositoryRefsChangedEvent;
12+
import com.atlassian.bitbucket.event.repository.RepositoryDeletedEvent;
1213
import com.atlassian.bitbucket.repository.RefChange;
1314
import com.atlassian.bitbucket.repository.RefChangeType;
1415
import com.atlassian.bitbucket.repository.Repository;
@@ -79,6 +80,17 @@ public void onRefsChanged(AbstractRepositoryRefsChangedEvent event) {
7980
}
8081
}
8182

83+
@EventListener
84+
public void onRepositoryDeleted(RepositoryDeletedEvent event) {
85+
Repository repo = event.getRepository();
86+
87+
Integer repoId = repo.getId();
88+
89+
log.info("RepositoryDeletedEvent: Delete all branch authors in a repo. repoId={}", repoId);
90+
91+
deleteAllBranchAuthor(repoId);
92+
}
93+
8294
private void createBranchAuthor(Integer repoId, Date created, String branchRef, Integer userId, String userEmail) {
8395
try {
8496
BranchAuthorImpl.saveBranchAuthor(activeObjects, repoId, created, branchRef, userId, userEmail);
@@ -94,4 +106,12 @@ private void deleteBranchAuthor(Integer repoId, String branchRef) {
94106
log.error("Deleting branch author error. repoid={}, branchRef={}", repoId, branchRef, e);
95107
}
96108
}
109+
110+
private void deleteAllBranchAuthor(Integer repoId) {
111+
try {
112+
BranchAuthorImpl.deleteAllBranchAuthor(activeObjects, repoId);
113+
} catch (SQLException e) {
114+
log.error("Deleting branch authors error. repoid={}", repoId, e);
115+
}
116+
}
97117
}

0 commit comments

Comments
 (0)