Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Repo Deletion #26

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions DEVNOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

### TODOs

* integrate webhook support (callback to accept POST, figure out repo, run git fetch on it), check security / DOS
* integrate webhook support (callback to accept POST, figure out repo, run git fetch on it) --> see [redmine_github_hook](https://github.com/koppen/redmine_github_hook) meanwhile
* check security / DOS
* key management (currently user needs to populate ~/.ssh/* config files manually)
* cleanup cloned repos on Repository#destroy
* make sure git fetch doesn't hang (timeout, background, local vs remote fetch interference)
* last fetched status, clearer error handling
* on plugin uninstall, Redmine will crash (rails hates it when you remove model classes)
* (provide a rake command to convert to Git type)
* initialize_clone should only run on new objects (since only "Main repository" is editable)
* key handling
* removing the plugin, what happens to records?
* on plugin uninstall, Redmine will crash (rails hates it when you remove model classes)
- provide a rake command to convert to Git type
- removing the plugin, what happens to records?
* conversion of legacy records


Expand Down
19 changes: 11 additions & 8 deletions app/models/repository/git_remote.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,7 @@ class Repository::GitRemote < Repository::Git
PATH_PREFIX = PLUGIN_ROOT + "/repos/"

before_validation :initialize_clone

# TODO: figure out how to do this safely (if at all)
# before_deletion :rm_removed_repo
# def rm_removed_repo
# if Repository.find_all_by_url(repo.url).length <= 1
# system "rm -Rf #{self.clone_path}"
# end
# end
before_destroy :remove_unused_repos

def extra_clone_url
return nil unless extra_info
Expand Down Expand Up @@ -85,6 +78,16 @@ def initialize_clone
errors.add :extra_clone_url, err if err
end

## Deletes repository directory if it's inside plugin directory (i.e. belongs to plugin)
## and this repo is not used by other repositories
def remove_unused_repos
inside_plugin_bundle = self.clone_path.include? PATH_PREFIX
nobody_else_need_it = Repository.where(url: self.url).count <= 1
if inside_plugin_bundle && nobody_else_need_it
system "rm -Rf #{self.clone_path}"
end
end

# equality check ignoring trailing whitespace and slashes
def two_remotes_equal(a,b)
a.chomp.gsub(/\/$/,'') == b.chomp.gsub(/\/$/,'')
Expand Down