in src/main/kotlin/org/jetbrains/teamcity/github/action/DeleteWebHookAction.kt [17:40]
fun doRun(info: GitHubRepositoryInfo, client: GitHubClientEx, context: ActionContext): HookDeleteOperationResult {
// 0. Check whether there any hooks for repo in local cache. Return of none in cache.
var hooks = context.storage.getHooks(info)
if (hooks.isEmpty()) return HookDeleteOperationResult.NeverExisted
// 1. Reload all hooks from GitHub
// It's ok throw GitHubAccessException upwards
GetAllWebHooksAction.doRun(info, client, context)
// 2. Remove missing hooks from storage as they don't exists remotely
context.storage.delete(info) { it.status == Status.MISSING }
hooks = context.storage.getHooks(info)
if (hooks.isEmpty()) return HookDeleteOperationResult.NeverExisted
val service = RepositoryServiceEx(client)
// 3. Run 'delete' action remotely
// 4. If case of insufficient permissions - run 'disable' action remotely
for (hook in hooks) {
doDeleteOrDisable(client, context, hook, info, service)
}
return HookDeleteOperationResult.Removed
}