asalom / swifttalking.com

https://www.swifttalking.com
MIT License
0 stars 0 forks source link

Add a Jira issue number to each git commit | Swift Talking #8

Open utterances-bot opened 5 years ago

utterances-bot commented 5 years ago

Add a Jira issue number to each git commit | Swift Talking

Most teams use some short of ticket system such as Jira or Trello. Learn how to add a JIRA ticket number to every git commit.

https://www.swifttalking.com/add-jira-issue-number-to-every-commit/

huzefa-amura commented 5 years ago

Hi Alex, Thanks for the awesome article. I have facing an issue with the hook file mentioned by you above which after debuggin found that the line grep -Eo "[A-Z0-9]{1,10}-?[A-Z0-9]+-\d+" doesn't work at all. I tried with different branch names also with same as yours too but doesn't work.

Whereas if i apply some other Regex, it works but doesn't give the desired output which just the ticket number. Can you please let me know what's the issue here?

asalom commented 5 years ago

Hello @huzefa-amura,

Thank you for taking the time to read the article.

What OS do you have?

Please, make sure that:

  1. The git hook is in the correct path and it has the correct name: .git/hooks/commit-msg
  2. The file has execute permissions and belongs to the correct user/group: -rwxr-xr-x 1 asalom staff commit-msg

Let me know if that helps

huzefa-amura commented 5 years ago

Hi Alex,

I am using Ubuntu 18.04.3 LTS.

  1. Yes hook is in the correct path and also gets executed. But regex doesn't work.
  2. Yes it has all required permissions.

Please let me know the issue here.

On Tue, 17 Sep, 2019, 18:26 Alex Salom, notifications@github.com wrote:

Hello @huzefa-amura https://github.com/huzefa-amura,

Thank you for taking the time to read the article.

What OS do you have?

Please, make sure that:

  1. The git hook is in the correct path and it has the correct name: .git/hooks/commit-msg
  2. The file has execute permissions and belongs to the correct user/group: -rwxr-xr-x 1 asalom staff commit-msg

Let me know if that helps

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/asalom/swifttalking.com/issues/8?email_source=notifications&email_token=AM25OJBKOW2H73RQOK5IEQDQKDHYJA5CNFSM4IXMS7E2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD64NVAA#issuecomment-532208256, or mute the thread https://github.com/notifications/unsubscribe-auth/AM25OJGE2XV74LKIQQRMEXDQKDHYJANCNFSM4IXMS7EQ .

-- Website http://www.amuratech.com  |  LinkedIn https://in.linkedin.com/company/amura-marketing-technologies-pvt-ltd  |  Facebook https://www.facebook.com/amuratech/  |  Instagram https://www.instagram.com/amuratech/?hl=en  |  Twitter https://twitter.com/amuratech?lang=en  | Contact: +91 20 3015 7034

DISCLAIMER: This message, including any attachments may contain proprietary, confidential and privileged information for the sole use of the intended recipient(s), and is protected by law. If you are not the intended recipient, please notify the sender immediately and destroy all copies of the original message and attachments, if any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this  email or any action taken in reliance on this e-mail is strictly prohibited and may be unlawful. Amura Marketing Technologies Pvt Ltd reserves the right to record, monitor and inspect all email communications through its internal and external networks. Your messages can be subject to such lawful supervision as it deems necessary in order to protect their information, interests and reputation. Please ensure you have adequate virus protection before you open or detach any documents from this transmission sender does not accept any liability for viruses.

asalom commented 5 years ago

Hi @huzefa-amura,

I think I figured out the issue. grep implementation is different for Mac and other Linux systems. The problem seems to be in the way it interprets non greedy (lazy) searches. While Mac's grep interprets them as non greedy by default, other Linux implementations don't. One way you could fix the issue you are having is by slightly modifying the command from the blog post:

echo “feature/APP-123_some_problem” | grep -Eo “[A-Z0-9]{1,10}-?[A-Z0-9]+-\d+”

into

echo “feature/APP-123_some_problem” | grep -Po “[A-Z0-9]{1,10}-?[A-Z0-9]+-\d+”

In the second command we are using -P option which means that grep will interpret the regular expression as a Perl-compatible regular expression (PCRE)

This is what the man grep page says about -P in my Raspberry PI:

-P, --perl-regexp Perl-compatible regular expression (PCRE). This is highly experimental and grep -P may warn of unimplemented features.

Let me know if this helps.

huzefa-amura commented 5 years ago

Hi Alex,

Thanks for the in-depth information and I have tried with -Po but it didn't work either. Let me know if you find the reason for the issue.

Thanks & Regards,

Huzefa S Biyawarwala, Team-Lead(Product Development) - Sell.do, Email: huzefa.biyawarwala@sell.do, Mob: +91 9408973369

On Wed, Sep 18, 2019 at 2:42 PM Alex Salom notifications@github.com wrote:

Hi @huzefa-amura https://github.com/huzefa-amura,

I think I figured out the issue. grep implementation is different for Mac and other Linux systems. The problem seems to be in the way it interprets non greedy (lazy) searches. While Mac's grep interprets them as non greedy by default, other Linux implementations don't. One way you could fix the issue you are having is by slightly modifying the command from the blog post:

echo “feature/APP-123_some_problem” | grep -Eo “[A-Z0-9]{1,10}-?[A-Z0-9]+-\d+”

into

echo “feature/APP-123_some_problem” | grep -Po “[A-Z0-9]{1,10}-?[A-Z0-9]+-\d+”

In the second command we are using -P option which means that grep will interpret the regular expression as a Perl-compatible regular expression (PCRE)

This is what the man grep page says about -P in my Raspberry PI:

-P, --perl-regexp Perl-compatible regular expression (PCRE). This is highly experimental and grep -P may warn of unimplemented features.

Let me know if this helps.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/asalom/swifttalking.com/issues/8?email_source=notifications&email_token=AM25OJDVOTE2GS4ZUCQ3FIDQKHWHRA5CNFSM4IXMS7E2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD67MOFQ#issuecomment-532596502, or mute the thread https://github.com/notifications/unsubscribe-auth/AM25OJDCP3JFBYGQLCS37XDQKHWHRANCNFSM4IXMS7EQ .

-- Website http://www.amuratech.com  |  LinkedIn https://in.linkedin.com/company/amura-marketing-technologies-pvt-ltd  |  Facebook https://www.facebook.com/amuratech/  |  Instagram https://www.instagram.com/amuratech/?hl=en  |  Twitter https://twitter.com/amuratech?lang=en  | Contact: +91 20 3015 7034

DISCLAIMER: This message, including any attachments may contain proprietary, confidential and privileged information for the sole use of the intended recipient(s), and is protected by law. If you are not the intended recipient, please notify the sender immediately and destroy all copies of the original message and attachments, if any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this  email or any action taken in reliance on this e-mail is strictly prohibited and may be unlawful. Amura Marketing Technologies Pvt Ltd reserves the right to record, monitor and inspect all email communications through its internal and external networks. Your messages can be subject to such lawful supervision as it deems necessary in order to protect their information, interests and reputation. Please ensure you have adequate virus protection before you open or detach any documents from this transmission sender does not accept any liability for viruses.

asalom commented 5 years ago

can you tell me what is the output of the following commands?

  1. echo "feature/APP-123_some_problem" | grep -Po "[A-Z0-9]{1,10}-?[A-Z0-9]+-\d+"
  2. echo "feature/APP-123_some_problem" | grep -Eo "[A-Z0-9]{1,10}-?[A-Z0-9]+-\d+"
huzefa-amura commented 5 years ago

Hi Alex,

So the outputs are as below:

  1. echo "feature/APP-123_some_problem" | grep -Po "[A-Z0-9]{1,10}-?[A-Z0-9]+-\d+" Output: [APP-123]

2.echo "feature/APP-123_some_problem" | grep -Eo "[A-Z0-9]{1,10}-?[A-Z0-9]+-\d+" Output: Nothing/Blank

The 1st one also worked when kept in hook file. I understood the problem when I saw my branch as it was abc-123 i.e. in lowercase. But when I created new branch with the upper case it worked. So you can add regex for 1st one as it is working solution. Thanks.

Thanks & Regards,

Huzefa S Biyawarwala, Team-Lead(Product Development) - Sell.do, Email: huzefa.biyawarwala@sell.do, Mob: +91 9408973369

On Fri, Sep 20, 2019 at 2:39 PM Alex Salom notifications@github.com wrote:

can you tell me what is the output of the following commands?

  1. echo "feature/APP-123_some_problem" | grep -Po "[A-Z0-9]{1,10}-?[A-Z0-9]+-\d+"
  2. echo "feature/APP-123_some_problem" | grep -Eo "[A-Z0-9]{1,10}-?[A-Z0-9]+-\d+"

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/asalom/swifttalking.com/issues/8?email_source=notifications&email_token=AM25OJHHZ6SQBDWSVZ3MAFDQKSHN3A5CNFSM4IXMS7E2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7GC3IQ#issuecomment-533474722, or mute the thread https://github.com/notifications/unsubscribe-auth/AM25OJAGS7NMUSLATFKLKULQKSHN3ANCNFSM4IXMS7EQ .

-- Website http://www.amuratech.com  |  LinkedIn https://in.linkedin.com/company/amura-marketing-technologies-pvt-ltd  |  Facebook https://www.facebook.com/amuratech/  |  Instagram https://www.instagram.com/amuratech/?hl=en  |  Twitter https://twitter.com/amuratech?lang=en  | Contact: +91 20 3015 7034

DISCLAIMER: This message, including any attachments may contain proprietary, confidential and privileged information for the sole use of the intended recipient(s), and is protected by law. If you are not the intended recipient, please notify the sender immediately and destroy all copies of the original message and attachments, if any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this  email or any action taken in reliance on this e-mail is strictly prohibited and may be unlawful. Amura Marketing Technologies Pvt Ltd reserves the right to record, monitor and inspect all email communications through its internal and external networks. Your messages can be subject to such lawful supervision as it deems necessary in order to protect their information, interests and reputation. Please ensure you have adequate virus protection before you open or detach any documents from this transmission sender does not accept any liability for viruses.

asalom commented 5 years ago

The first command outputs the right string. Perhaps the problem is now elsewhere. Can you debug again using the command with -Po?

For a commit message This is a commit, the hook should update it to [APP-123] This is a commit

huzefa-amura commented 5 years ago

Yes Alex,

It outputs correctly but only for branches whose name are in Upper case. Problem is my branch name is in lower-case hence it doesn't give any output.

On Fri, 20 Sep, 2019, 15:34 Alex Salom, notifications@github.com wrote:

The first command outputs the right string. Perhaps the problem is now elsewhere. Can you debug again using the command with -Po?

For a commit message This is a commit, the hook should update it to [APP-123] This is a commit

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/asalom/swifttalking.com/issues/8?email_source=notifications&email_token=AM25OJGZS2FAIOQLCEA5GV3QKSN3TA5CNFSM4IXMS7E2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7GHKBY#issuecomment-533492999, or mute the thread https://github.com/notifications/unsubscribe-auth/AM25OJEPF3ZL5DM22A7YYCDQKSN3TANCNFSM4IXMS7EQ .

-- Website http://www.amuratech.com  |  LinkedIn https://in.linkedin.com/company/amura-marketing-technologies-pvt-ltd  |  Facebook https://www.facebook.com/amuratech/  |  Instagram https://www.instagram.com/amuratech/?hl=en  |  Twitter https://twitter.com/amuratech?lang=en  | Contact: +91 20 3015 7034

DISCLAIMER: This message, including any attachments may contain proprietary, confidential and privileged information for the sole use of the intended recipient(s), and is protected by law. If you are not the intended recipient, please notify the sender immediately and destroy all copies of the original message and attachments, if any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this  email or any action taken in reliance on this e-mail is strictly prohibited and may be unlawful. Amura Marketing Technologies Pvt Ltd reserves the right to record, monitor and inspect all email communications through its internal and external networks. Your messages can be subject to such lawful supervision as it deems necessary in order to protect their information, interests and reputation. Please ensure you have adequate virus protection before you open or detach any documents from this transmission sender does not accept any liability for viruses.

asalom commented 5 years ago

If you type man grep you can find all the options grep has. One of them is -i which makes the regex ignore the case of the string is checking. If you add that, it won't matter whether the Jira ticket is upper or lowercase

echo "feature/app-123_some_problem" | grep -Poi "[A-Z0-9]{1,10}-?[A-Z0-9]+-\d+"
huzefa-amura commented 5 years ago

Ok, Thanks,

That worked. I would suggest you update it on your article too as someone might run into the same issue as mine. Thanks for this help Alex, very much appreciated.

Thanks & Regards,

Huzefa S Biyawarwala, Team-Lead(Product Development) - Sell.do, Email: huzefa.biyawarwala@sell.do, Mob: +91 9408973369

On Fri, Sep 20, 2019 at 4:56 PM Alex Salom notifications@github.com wrote:

If you type man grep you can find all the options grep has. One of them is -i which makes the regex ignore the case. If you add that, it won't matter whether the Jira ticket is upper or lowercase

echo "feature/app-123_some_problem" | grep -Poi "[A-Z0-9]{1,10}-?[A-Z0-9]+-\d+"

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/asalom/swifttalking.com/issues/8?email_source=notifications&email_token=AM25OJDU2HOZOXDPZDW3N33QKSXORA5CNFSM4IXMS7E2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7GMXBI#issuecomment-533515141, or mute the thread https://github.com/notifications/unsubscribe-auth/AM25OJECHFO6MJZUKU74GRTQKSXORANCNFSM4IXMS7EQ .

-- Website http://www.amuratech.com  |  LinkedIn https://in.linkedin.com/company/amura-marketing-technologies-pvt-ltd  |  Facebook https://www.facebook.com/amuratech/  |  Instagram https://www.instagram.com/amuratech/?hl=en  |  Twitter https://twitter.com/amuratech?lang=en  | Contact: +91 20 3015 7034

DISCLAIMER: This message, including any attachments may contain proprietary, confidential and privileged information for the sole use of the intended recipient(s), and is protected by law. If you are not the intended recipient, please notify the sender immediately and destroy all copies of the original message and attachments, if any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this  email or any action taken in reliance on this e-mail is strictly prohibited and may be unlawful. Amura Marketing Technologies Pvt Ltd reserves the right to record, monitor and inspect all email communications through its internal and external networks. Your messages can be subject to such lawful supervision as it deems necessary in order to protect their information, interests and reputation. Please ensure you have adequate virus protection before you open or detach any documents from this transmission sender does not accept any liability for viruses.

asalom commented 5 years ago

Glad to hear! And thanks for the suggestion!