Skip to content

Commit

Permalink
Support repository deletion.
Browse files Browse the repository at this point in the history
  • Loading branch information
wadahiro committed Jan 25, 2016
1 parent d265e2d commit 12115eb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,12 @@ public static void deleteBranchAuthor(ActiveObjects ao, Integer repoId, String b
ao.delete(branchAuthors[0]);
}
}

public static void deleteAllBranchAuthor(ActiveObjects ao, Integer repoId) throws SQLException {
BranchAuthor[] branchAuthors = ao.find(BranchAuthor.class, Query.select().where("REPO_ID = ?", repoId));

for (BranchAuthor branchAuthor : branchAuthors) {
ao.delete(branchAuthor);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import com.atlassian.activeobjects.external.ActiveObjects;
import com.atlassian.bitbucket.event.repository.AbstractRepositoryRefsChangedEvent;
import com.atlassian.bitbucket.event.repository.RepositoryDeletedEvent;
import com.atlassian.bitbucket.repository.RefChange;
import com.atlassian.bitbucket.repository.RefChangeType;
import com.atlassian.bitbucket.repository.Repository;
Expand Down Expand Up @@ -79,6 +80,17 @@ public void onRefsChanged(AbstractRepositoryRefsChangedEvent event) {
}
}

@EventListener
public void onRepositoryDeleted(RepositoryDeletedEvent event) {
Repository repo = event.getRepository();

Integer repoId = repo.getId();

log.info("RepositoryDeletedEvent: Delete all branch authors in a repo. repoId={}", repoId);

deleteAllBranchAuthor(repoId);
}

private void createBranchAuthor(Integer repoId, Date created, String branchRef, Integer userId, String userEmail) {
try {
BranchAuthorImpl.saveBranchAuthor(activeObjects, repoId, created, branchRef, userId, userEmail);
Expand All @@ -94,4 +106,12 @@ private void deleteBranchAuthor(Integer repoId, String branchRef) {
log.error("Deleting branch author error. repoid={}, branchRef={}", repoId, branchRef, e);
}
}

private void deleteAllBranchAuthor(Integer repoId) {
try {
BranchAuthorImpl.deleteAllBranchAuthor(activeObjects, repoId);
} catch (SQLException e) {
log.error("Deleting branch authors error. repoid={}", repoId, e);
}
}
}

0 comments on commit 12115eb

Please sign in to comment.