10
10
import com .atlassian .activeobjects .external .ActiveObjects ;
11
11
import com .atlassian .event .api .EventListener ;
12
12
import com .atlassian .stash .event .AbstractRepositoryRefsChangedEvent ;
13
+ import com .atlassian .stash .event .RepositoryDeletedEvent ;
13
14
import com .atlassian .stash .repository .RefChange ;
14
15
import com .atlassian .stash .repository .RefChangeType ;
15
16
import com .atlassian .stash .repository .Repository ;
@@ -29,16 +30,15 @@ public BranchListener(ActiveObjects activeObjects) {
29
30
}
30
31
31
32
/**
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.
34
36
* Using AbstractRepositoryRefsChangedEvent, we can support following operations.
35
37
*
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
42
42
* Branch deletion by fork syncing
43
43
*
44
44
* @param event
@@ -79,6 +79,17 @@ public void onRefsChanged(AbstractRepositoryRefsChangedEvent event) {
79
79
}
80
80
}
81
81
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
+
82
93
private void createBranchAuthor (Integer repoId , Date created , String branchRef , Integer userId , String userEmail ) {
83
94
try {
84
95
BranchAuthorImpl .saveBranchAuthor (activeObjects , repoId , created , branchRef , userId , userEmail );
@@ -94,4 +105,12 @@ private void deleteBranchAuthor(Integer repoId, String branchRef) {
94
105
log .error ("Deleting branch author error. repoid={}, branchRef={}" , repoId , branchRef , e );
95
106
}
96
107
}
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
+ }
97
116
}
0 commit comments