tf / redmine_merge_request_links

Display links to associated Gitlab merge requests and GitHub pull requests on Redmine's issue page.
https://www.redmine.org/plugins/redmine_merge_request_links
MIT License
35 stars 26 forks source link

Does not work when issue has associated revisions #7

Closed tofi86 closed 6 years ago

tofi86 commented 6 years ago

When using "repositories" in Redmine to view GitLab/GitHub repos in Redmine and associate changesets/commits with issues, and if the issue has associated revisions the associated merge requests panel is not shown. In other cases it works.

Part of the payload:

"description"=>"betrifft #7664\r\n"

The issue 7664 has an associated changeset.

No errors in logfile are shown.

After refreshing the MR and refreshing Redmine the associated MR is not shown in issue 7664.

tf commented 6 years ago

Issue ids are only looked for inside the MR title and description - not inside messages of the MR's commits. GitLab does not include commit information in merge request webhooks and that's the only source of information currently used by the plugin. Does that explain the observed behavior? Otherwise I'd need a more complete example of a webhook payload that is not processed correctly.

tf commented 6 years ago

Can you give me a quick feedback if what I described applies to your case? Then we can either label the issue as a feature request for future reference, add it to the list of known issues in the readme or both.

tofi86 commented 6 years ago

If you use the "Repositories" Feature in Redmine you can specify a project VCS (git, svn) on a local path which is then accessible within Redmine (example: http://www.redmine.org/projects/redmine/repository)

Commit messages can hold issue references with keywords and then the commit get's linked to the issue and is shown like this:

http://www.redmine.org/issues/28829#issue-changesets

This is my case:

grafik

This issue has a associated revision AND it has an associated merge request, but the merge request box is not shown at all.

tf commented 6 years ago

But does the merge request actually mention the issue id either in its title or description? If the issue id is only mentioned in a commit message, the commit will be associated with the issue, but the merge request won't. Establishing this association would be possible, but would require fetching commit data from GitLab via the REST API since not all commits of a merge request are passed in the GitLab webhook. And this webhook is the only source of information this plugin uses at the moment.

tofi86 commented 6 years ago

But does the merge request actually mention the issue id either in its title or description?

Yes. See the paylod snippet above. This is the total description from the MR, there's nothing more than betrifft #7664\r\n.

tofi86 commented 6 years ago

If I remove the commit association the associated MR isn't shown either.

If I update the MR description afterwards, the MR isn't linked in the issue either.

So maybe something is wrong with parsing this kinda short MR description or I have no idea...

This is the log excerpt with the payload:

Started POST "/merge_requests/event" for 185.21.100.83 at 2018-09-19 12:12:07 +0200
Processing by MergeRequestsController#event as HTML
  Parameters: {"object_kind"=>"merge_request", "event_type"=>"merge_request", "user"=>{"name"=>"Tobias Fischer", "username"=>"tofi", "avatar_url"=>"https://secure.gravatar.com/avatar/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa?s=80&d=identicon"}, "project"=>{"id"=>17, "name"=>"Konverter", "description"=>"project description", "web_url"=>"https://sub.host.tld/group/project-name", "avatar_url"=>nil, "git_ssh_url"=>"git@sub.host.tld:group/project-name.git", "git_http_url"=>"https://sub.host.tld/group/project-name.git", "namespace"=>"group", "visibility_level"=>0, "path_with_namespace"=>"group/project-name", "default_branch"=>"master", "ci_config_path"=>nil, "homepage"=>"https://sub.host.tld/group/project-name", "url"=>"git@sub.host.tld:group/project-name.git", "ssh_url"=>"git@sub.host.tld:group/project-name.git", "http_url"=>"https://sub.host.tld/group/project-name.git"}, "object_attributes"=>{"assignee_id"=>1, "author_id"=>1, "created_at"=>"2017-07-13 12:51:25 UTC", "description"=>"betrifft #7664\r\n\r\n", "head_pipeline_id"=>nil, "id"=>137, "iid"=>5, "last_edited_at"=>"2018-09-19 10:12:07 UTC", "last_edited_by_id"=>1, "merge_commit_sha"=>nil, "merge_error"=>nil, "merge_params"=>{"force_remove_source_branch"=>"1"}, "merge_status"=>"cannot_be_merged", "merge_user_id"=>nil, "merge_when_pipeline_succeeds"=>false, "milestone_id"=>nil, "source_branch"=>"dev/7664-AH-AreaTree", "source_project_id"=>17, "state"=>"opened", "target_branch"=>"development", "target_project_id"=>17, "time_estimate"=>0, "title"=>"WIP: AH AreaTree ausgeben (im DebugMode)", "updated_at"=>"2018-09-19 10:12:07 UTC", "updated_by_id"=>1, "url"=>"https://sub.host.tld/group/project-name/merge_requests/5", "source"=>{"id"=>17, "name"=>"Konverter", "description"=>"project description", "web_url"=>"https://sub.host.tld/group/project-name", "avatar_url"=>nil, "git_ssh_url"=>"git@sub.host.tld:group/project-name.git", "git_http_url"=>"https://sub.host.tld/group/project-name.git", "namespace"=>"group", "visibility_level"=>0, "path_with_namespace"=>"group/project-name", "default_branch"=>"master", "ci_config_path"=>nil, "homepage"=>"https://sub.host.tld/group/project-name", "url"=>"git@sub.host.tld:group/project-name.git", "ssh_url"=>"git@sub.host.tld:group/project-name.git", "http_url"=>"https://sub.host.tld/group/project-name.git"}, "target"=>{"id"=>17, "name"=>"Konverter", "description"=>"project description", "web_url"=>"https://sub.host.tld/group/project-name", "avatar_url"=>nil, "git_ssh_url"=>"git@sub.host.tld:group/project-name.git", "git_http_url"=>"https://sub.host.tld/group/project-name.git", "namespace"=>"group", "visibility_level"=>0, "path_with_namespace"=>"group/project-name", "default_branch"=>"master", "ci_config_path"=>nil, "homepage"=>"https://sub.host.tld/group/project-name", "url"=>"git@sub.host.tld:group/project-name.git", "ssh_url"=>"git@sub.host.tld:group/project-name.git", "http_url"=>"https://sub.host.tld/group/project-name.git"}, "last_commit"=>{"id"=>"68112f559b321988632bbd68780292f788208c87", "message"=>"nachtrag\n", "timestamp"=>"2017-07-13T12:53:56Z", "url"=>"https://sub.host.tld/group/project-name/commit/68112f559b321988632bbd68780292f788208c87", "author"=>{"name"=>"Tobias Fischer", "email"=>"tobias.fischer@host.tld"}}, "work_in_progress"=>true, "total_time_spent"=>0, "human_total_time_spent"=>nil, "human_time_estimate"=>nil, "action"=>"update"}, "labels"=>[{"id"=>106, "title"=>"status:postponed", "color"=>"#D1D100", "project_id"=>nil, "created_at"=>"2018-09-12 09:07:23 UTC", "updated_at"=>"2018-09-12 09:07:23 UTC", "template"=>false, "description"=>"Zurückgestellt", "type"=>"GroupLabel", "group_id"=>2}, {"id"=>110, "title"=>"type:feature", "color"=>"#69D100", "project_id"=>nil, "created_at"=>"2018-09-12 09:07:48 UTC", "updated_at"=>"2018-09-12 09:07:48 UTC", "template"=>false, "description"=>"", "type"=>"GroupLabel", "group_id"=>2}], "changes"=>{"description"=>{"previous"=>"betrifft #7664\r\n", "current"=>"betrifft #7664\r\n\r\n"}, "last_edited_at"=>{"previous"=>"2018-09-17 21:32:26 UTC", "current"=>"2018-09-19 10:12:07 UTC"}, "updated_at"=>{"previous"=>"2018-09-17 21:32:26 UTC", "current"=>"2018-09-19 10:12:07 UTC"}}, "repository"=>{"name"=>"Konverter", "url"=>"git@sub.host.tld:group/project-name.git", "description"=>"project description", "homepage"=>"https://sub.host.tld/group/project-name"}, "assignee"=>{"name"=>"Tobias Fischer", "username"=>"tofi", "avatar_url"=>"https://secure.gravatar.com/avatar/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa?s=80&d=identicon"}}
  Current user: anonymous
Completed 200 OK in 46ms (ActiveRecord: 3.5ms)
tofi86 commented 6 years ago

When looking at the redmine database, the table merge_requests already has an entry for this MR:

"3" "gitlab"    "WIP: AH AreaTree ausgeben (im DebugMode)"  "https://sub.host.tld/group/project-name/merge_requests/5"  "opened"    "@tofi" "group/project-name!5"

And table issues_merge_requests has also an entry:

"7664"  "3"

Still, the MR box is not shown.

tofi86 commented 6 years ago

Bummer! Got it! Trapped by my own changes to this project, sor sorry!

The current project does not have repositories definied, but the parent project has. That's why Associated revisions work in this issue, but the MR does not. If I active Redmine module "repositories" for this sub-project, everything works as expected.

This is because of my permission "fix":

https://github.com/tf/redmine_merge_request_links/blob/master/app/views/merge_request_links/_box.html.erb#L1

@project is the wrong context here... :-/

Either we have to resolve project inheritance here or use custom project wide permissions by user role.

tf commented 6 years ago

So the user does not have the browse_repository permission in the project, because the project does not have the repository module enabled? I guess we need to come up with a custom permission then. Looking for permissions in parent projects sounds too complicated to me.

tf commented 6 years ago

We should probably also add a project module then.

tofi86 commented 6 years ago

So the user does not have the browse_repository permission in the project, because the project does not have the repository module enabled?

exactly!

I guess we need to come up with a custom permission then.

+1

tf commented 6 years ago

Released as part of 2.0. See changelog for upgrade instructions.

tofi86 commented 6 years ago

Awesome, thanks! :)