Skip to content

Instantly share code, notes, and snippets.

@sbimochan
Last active January 16, 2023 13:36
Show Gist options
  • Save sbimochan/c8d3aa8de3bfec47051c14f6459a328a to your computer and use it in GitHub Desktop.
Save sbimochan/c8d3aa8de3bfec47051c14f6459a328a to your computer and use it in GitHub Desktop.
Get All unique commits going to staging branch from dev or other

Make sure you pulled all the commits in dev and staging branch

Approriately change if needed for master and staging.

git log origin/staging..origin/dev --oneline --no-merges

Press enter and grab all the result in clipboard

Fire up the console

Store the result in a variable like this. Make sure there are no tilds in the result.

const commits = `CPT-1233: I did something
CPT-4312: You did something`

Modify CPT or DGN according to your jira prefix

const regex = /[CPT,DGN,AP,MBC,DVOP]{2,}-\d{2,}/g
const branches = commits.match(regex)

const branchArray = Array.from(new Set(branches))

const sortedTickets = branchArray.sort(function(a, b) {
  let numA = parseInt(a.split('-')[1]);
  let numB = parseInt(b.split('-')[1]);
  return numA - numB;
});

sortedTickets.join(', ')

You get the unique branches that are going to staging

Bonus:

you can also generate a JQL from above result like below:

"fixVersion = 'v5.9.0 AP Sprint 1 Release' AND key NOT IN ('AP-508', 'CPT-102') order by key ASC"

where 'AP-508', 'CPT-102' can be the result from above and needs to have proper version and sprint

@sbimochan
Copy link
Author

sbimochan commented Jan 16, 2023

@Lazercat Thanks for the suggestion. I'll be implementing the sort right away although .sort() won't immediately work in our case. I'm still thinking how we can generate a JQL from it because it requires to have fix version. Sorry that I'm removing your comment that has our atlassian link since this is a public gist but let's connect in slack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment