Last active
November 12, 2019 20:42
-
-
Save jeremylenz/4e59dc0dbec15a39989cc1d06fac0aae to your computer and use it in GitHub Desktop.
Regex helpers to use in Zapier zaps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// match 5 or more digit characters | |
export const extractRMNum = (taskTitle) => { | |
const result = taskTitle.match(/\d{5,}/); | |
if (result) return result[0]; | |
return null; | |
} | |
// match https://github.com/{orgName}/{repoNameWithZeroOrOneHyphen}/pull/{1 or more digit chars} | |
export const extractGithubPrUrl = (taskNotes) => { | |
const result = taskNotes.match(/https:\/\/github\.com\/\w+\/\w+-*\w*\/pull\/\d+/); | |
if (result) return result[0]; | |
return null; | |
} | |
// match 1 or more digit characters after pull/ | |
export const extractPRNum = (hrefStr) => { | |
const result = hrefStr.match(/https:\/\/.{0,4}github\.com\/(\w+\/\w+[-_]*\w*)\/pull\/(\d+)/); | |
if (result && result.length > 1) return result[result.length - 1]; | |
return null; | |
} | |
// get full repo name from Github URL | |
export const extractFullRepoName = (hrefStr) => { | |
const result = hrefStr.match(/https:\/\/.{0,4}github\.com\/(\w+\/\w+-*\w*)/); | |
if (result && result.length > 1) return result[1]; | |
return null; | |
} | |
export const pullRequestInfo = (hrefStr) => { | |
const prLink = extractGithubPrUrl(hrefStr); | |
let prNum, repoName; | |
if (prLink) { | |
prNum = extractPRNum(prLink); | |
repoName = extractFullRepoName(prLink); | |
} | |
return { | |
found: (!!prLink && !!prNum && !!repoName), | |
url: prLink, | |
pullRequestNumber: prNum, | |
fullRepoName: repoName, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment