linniksa / redmine_git_mirror

Adds ability to clone and fetch remote git repositories to redmine
MIT License
35 stars 20 forks source link

Feature : Fetch changes when redmine show repo #9

Open GuillaumeFegeFullElec opened 5 years ago

GuillaumeFegeFullElec commented 5 years ago

Hi, thanks for the plugin.

Is there a possibility to fetch repo changes when a redmine user ask for a repo in the web interface ?

It could be usefull when redmine is on a host that do not support cron (docker for example) and when the git is not from github.

linniksa commented 5 years ago

You can comment this line: https://github.com/linniksa/redmine_git_mirror/blob/782a58abd6faa3d76cf45aa4815d5914ca462437/app/models/repository/git_mirror.rb#L125 and fetching on page open start working, but it increases page load time significantly

you can set up git hook which do http call to redmine.site/sys/git_mirror/fetch?url=[repo-url] or cron task on any server that do same thing

douglasoliveiraadv commented 4 years ago

Hi!

I have this plugin set up in my redmine and it's working fine with Amazon CodeCommit, but how can I use this url (redmine.site/sys/git_mirror/fetch?url=[repo-url) to fetch a repository on Amazon CodeCommit?

Thank you all!

douglasoliveiraadv commented 4 years ago

I'm trying but always returns error:

Started GET "/sys/git_mirror/fetch?url=git-codecommit.us-east-1.amazonaws.com/v1/repos/xxxxxxxxxxxxxxxxxx" for 187.64.122.71 at 2019-11-12 00:34:27 -0300 Processing by GitMirrorController#fetch as HTML Parameters: {"url"=>"git-codecommit.us-east-1.amazonaws.com/v1/repos/xxxxxxxxxxxxxxxxxx"} Completed 500 Internal Server Error in 2ms (ActiveRecord: 0.0ms)

NoMethodError (undefined method `each' for #):

plugins/redmine_git_mirror/app/controllers/git_mirror_controller.rb:98:in fetch_by_urls' plugins/redmine_git_mirror/app/controllers/git_mirror_controller.rb:6:infetch'

Thanks for the plugin!

linniksa commented 4 years ago

@douglasoliveiraadv try latest master, also specify url with scheme http://git-codecommit.us-east-1.amazonaws.com/v1/repos/xxxxxxxxxxxxxxxxxx or //git-codecommit.us-east-1.amazonaws.com/v1/repos/xxxxxxxxxxxxxxxxxx

douglasoliveiraadv commented 4 years ago

Thanks for the answer!

I am using version 0.8.0.

I just tried:

Started GET "/sys/git_mirror/fetch?url=ssh//git-codecommit.us-east-1.amazonaws.com/v1/repos/xxxxxxxxxxxxx" for 187.64.122.71 at 2019-11-12 02:16:55 -0300 Processing by GitMirrorController#fetch as HTML Parameters: {"url"=>"ssh//git-codecommit.us-east-1.amazonaws.com/v1/repos/xxxxxxxxxxxxx"} Completed 500 Internal Server Error in 3ms (ActiveRecord: 0.0ms)

NoMethodError (undefined method `each' for #):

plugins/redmine_git_mirror/app/controllers/git_mirror_controller.rb:98:in fetch_by_urls' plugins/redmine_git_mirror/app/controllers/git_mirror_controller.rb:6:infetch'

Started GET "/sys/git_mirror/fetch?url=//git-codecommit.us-east-1.amazonaws.com/v1/repos/xxxxxxxxxxxxx" for 187.64.122.71 at 2019-11-12 02:17:05 -0300 Processing by GitMirrorController#fetch as HTML Parameters: {"url"=>"//git-codecommit.us-east-1.amazonaws.com/v1/repos/xxxxxxxxxxxxx"} Completed 500 Internal Server Error in 2ms (ActiveRecord: 0.0ms)

NoMethodError (undefined method `each' for #):

plugins/redmine_git_mirror/app/controllers/git_mirror_controller.rb:98:in fetch_by_urls' plugins/redmine_git_mirror/app/controllers/git_mirror_controller.rb:6:infetch'

Started GET "/sys/git_mirror/fetch?url=http//git-codecommit.us-east-1.amazonaws.com/v1/repos/xxxxxxxxxxxxx" for 187.64.122.71 at 2019-11-12 02:17:10 -0300 Processing by GitMirrorController#fetch as HTML Parameters: {"url"=>"http//git-codecommit.us-east-1.amazonaws.com/v1/repos/xxxxxxxxxxxxx"} Completed 500 Internal Server Error in 2ms (ActiveRecord: 0.0ms)

NoMethodError (undefined method `each' for #):

plugins/redmine_git_mirror/app/controllers/git_mirror_controller.rb:98:in fetch_by_urls' plugins/redmine_git_mirror/app/controllers/git_mirror_controller.rb:6:infetch'

Started GET "/sys/git_mirror/fetch?url=htts//git-codecommit.us-east-1.amazonaws.com/v1/repos/xxxxxxxxxxxxx" for 187.64.122.71 at 2019-11-12 02:17:14 -0300 Processing by GitMirrorController#fetch as HTML Parameters: {"url"=>"htts//git-codecommit.us-east-1.amazonaws.com/v1/repos/xxxxxxxxxxxxx"} Completed 500 Internal Server Error in 2ms (ActiveRecord: 0.0ms)

NoMethodError (undefined method `each' for #):

plugins/redmine_git_mirror/app/controllers/git_mirror_controller.rb:98:in fetch_by_urls' plugins/redmine_git_mirror/app/controllers/git_mirror_controller.rb:6:infetch'

Does not work = \

How can I fix this?

Thank you again!

linniksa commented 4 years ago

i push commit with fix to master branch - 35d2cef, you need to pull it

cd plugins/redmine_git_mirror && git checkout master && git pull
douglasoliveiraadv commented 4 years ago

Hello!

I pulled, ran bundle exec rake redmine: plugins: migrate RAILS_ENV = production, did touch tmp/restar.txt and now it looks like this:

Started GET "/sys/git_mirror/fetch?url=ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/xxxxxxxxxx" for 187.64.122.71 at 2019-11-12 02:51:35 -0300Processing by GitMirrorController # fetch as HTML   Parameters: {"url" => "ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/xxxxxxxxxx"} Completed 404 Not Found in 3ms (ActiveRecord: 1.1ms)

Started GET "/sys/git_mirror/fetch?url=//git-codecommit.us-east-1.amazonaws.com/v1/repos/xxxxxxxxxx" for 187.64.122.71 at 2019-11-12 02:51:48 - 0300 Processing by GitMirrorController # fetch as HTML Parameters: {"url" => "//git-codecommit.us-east-1.amazonaws.com/v1/repos/xxxxxxxxxx"} Completed 404 Not Found in 3ms (ActiveRecord: 0.5ms )

Started GET "/sys/git_mirror/fetch?url=https://git-codecommit.us-east-1.amazonaws.com/v1/repos/xxxxxxxxxx" for 187.64.122.71 at 2019-11-12 02:51:51 -0300 Processing by GitMirrorController # fetch as HTML Parameters: {"url" => "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/xxxxxxxxxx"} Completed 404 Not Found in 3ms (ActiveRecord: 0.5ms)

Started GET "/sys/git_mirror/fetch?url=http://git-codecommit.us-east-1.amazonaws.com/v1/repos/xxxxxxxxxx" for 187.64. 122.71 at 2019-11-12 02:51:58 -0300 Processing by GitMirrorController # fetch as HTML Parameters: {"url" => "http://git-codecommit.us-east-1.amazonaws.com/v1/repos/xxxxxxxxxx "} Completed 404 Not Found in 3ms (ActiveRecord: 0.5ms)

What do I need to do? :( Thanks again!

linniksa commented 4 years ago

http 404 status code means that plugin can't find the repository by url

check that the url's you specify for clone in redmine and provided in hook is similar - same schema, username, and path.

douglasoliveiraadv commented 4 years ago

I made it. In my repository settings I use:

ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/xxxxxxxxxx

But always returns not found.

We need webhook because we use a lot of repositories and the cronjob I set up requires a lot of processing because every two hours it tries to update all repositories.

Thanks for your help!