Created
February 8, 2023 19:53
-
-
Save tzach/83de1d9d6fdec161fddf55e1d9370e3e to your computer and use it in GitHub Desktop.
replace github issues with links
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
var issuePrefix = "https://github.com/scylladb/scylladb/issues/" | |
function replaceWithLink(s) { | |
var regExp = new RegExp("([0-9]+)","gi"); | |
var isseuNumber = regExp.exec(s)[0]; | |
return ("#" + isseuNumber); | |
} | |
function test() { | |
var r = replaceWithLink("https://github.com/scylladb/scylla/issues/1076"); | |
Logger.log("res:" + r); | |
} | |
function replaceWithLinkInDoc(){ | |
Logger.log("start"); | |
let body = DocumentApp.getActiveDocument().getBody(); | |
let reg = issuePrefix + '([0-9]+)'; | |
let searchResult = body.findText(reg); | |
while (searchResult != null) { | |
const textElement = searchResult.getElement().asText(); | |
const p = textElement.getText(); | |
const issue = p.match(reg)[0]; | |
const start = p.search(reg); | |
let newIssue = replaceWithLink(issue); | |
Logger.log("newIssue:" + newIssue); | |
textElement.replaceText(reg,newIssue); | |
textElement.setLinkUrl(start, start + 5 , issue) // TBD: assume issue if 5 digits | |
// Find the next match | |
searchResult = body.findText(reg); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment