Skip to content
This repository has been archived by the owner on Feb 5, 2018. It is now read-only.

Merge Request ID for GitLab #29

Closed
hutson opened this issue Aug 7, 2016 · 5 comments
Closed

Merge Request ID for GitLab #29

hutson opened this issue Aug 7, 2016 · 5 comments

Comments

@hutson
Copy link

hutson commented Aug 7, 2016

I created a merge request on GitLab, leaving the title of the merge request as the default (the header line of my commit). Therefore it was Docs/readme.

Upon accepting the merge request I ended up with a merge commit in my history that looks like:

commit ccc375b33f12355db58d5af81d63ab84e843ab59
Merge: 594e972 aaf372a
Author: Hutson Betts <hutson@hyper-expanse.net>
Date:   Sun Aug 7 03:23:26 2016 +0000

    Merge branch 'docs/readme' into 'master'

    Docs/readme



    See merge request !1

When running the commit through conventional-commits-parser I end up with the following commit object:

{ type: null,
  scope: null,
  subject: null,
  merge: null,
  header: 'Merge branch \'docs/readme\' into \'master\'',
  body: 'Docs/readme\n\n\n\nSee merge request !1',
  footer: null,
  notes: [],
  references: [],
  mentions: [],
  revert: null }

It seems the line containing !1 is not parsed out.

I changed issuePrefix to include !, but since the merge request ID is not part of the footer, I can't get the merge request ID as an issue reference.

@stevemao
Copy link
Collaborator

stevemao commented Aug 8, 2016

what's your referenceActions?

@hutson
Copy link
Author

hutson commented Aug 8, 2016

The commit object in my initial comment is based on calling the parser without any custom configuration.

I then modified the issuePrefix configuration property in an attempt to get the merge request ID, to no avail.

I then, based on your suggestion, modified the referenceActions property, with and without modifying issuePrefix, and still not able to get the merge request ID. (I set referenceActions to See merge request.)

@stevemao
Copy link
Collaborator

stevemao commented Aug 9, 2016

Why don't you use mergePattern and mergeCorrespondence?

If you treat it as a reference it should still work. Can you set a break point at https://github.com/conventional-changelog/conventional-commits-parser/blob/master/lib/parser.js#L99-L127 and see what you've got?

@hutson
Copy link
Author

hutson commented Aug 10, 2016

@stevemao thanks for the pointer! I'll give that a try next.

I haven't had an opportunity to look into mergePattern yet while I was investigating this issue: conventional-changelog/releaser-tools#22

@hutson
Copy link
Author

hutson commented Aug 18, 2016

Provided custom values for the suggested arguments as shown below:

{
  mergePattern: /^Merge branch '(.*)' into '(.*)'$/,
  mergeCorrespondence: ['source', 'destination'],
}

With that I received the following commit object for the merge commit:

{ type: null,
  scope: null,
  subject: null,
  source: 'docs/readme',
  destination: 'master',
  merge: 'Merge branch \'docs/readme\' into \'master\'',
  header: 'Docs/readme',
  body: 'See merge request !1',
  footer: null,
  notes: [],
  references: [],
  mentions: [],
  revert: null }

So it's now successfully detecting the merge header.

That still doesn't give me access to the merge request ID.

Therefore I extended the custom options:

{
  mergePattern: /^Merge branch '(.*)' into '(.*)'$/,
  mergeCorrespondence: ['source', 'destination'],
  issuePrefixes: ['#', '!'],
  referenceActions: [ 'close', 'closes', 'closed', 'fix', 'fixes', 'fixed', 'resolve', 'resolves', 'resolved', 'See merge request' ]

By specifying the issuePrefixes and referenceActions I get the following:

{ type: null,
  scope: null,
  subject: null,
  source: 'docs/readme',
  destination: 'master',
  merge: 'Merge branch \'docs/readme\' into \'master\'',
  header: 'Docs/readme',
  body: null,
  footer: 'See merge request !1',
  notes: [],
  references:
   [ { action: 'See merge request',
       owner: null,
       repository: null,
       issue: '1',
       raw: '!1',
       prefix: '!' } ],
  mentions: [],
  revert: null }

So as you noted, that gives me access to the ID number, and I can tell it's a merge request because of the prefix.

Oddly, now, if I just set the issuePrefixes and referenceActions I get the same reference object. It doesn't seem I need to override mergePattern and mergeCorrespondence. Not sure why I wasn't able to get the merge request ID as noted in my earlier comment.

I must have made a mistake somewhere then.

I'll be able to move forward with my own project now that I can get at the merge ID.

Thank you for your help with tackling my issue.

@hutson hutson closed this as completed Aug 18, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants