Last active
March 13, 2023 20:51
-
-
Save SourcingDenis/44ad36e3182e9657ded134557a84035d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function getGitHubRepoUrl() { | |
var sheet = SpreadsheetApp.getActiveSheet(); | |
var range = sheet.getActiveRange(); | |
var username = range.getValue(); | |
var adjacentCell = range.offset(0, 1); // adjust this if the URL is in a different column | |
var repoUrl = ""; | |
if (username.indexOf("github.com") >= 0) { | |
username = username.replace(/^.*com[/]([^/]*).*$/,'$1'); | |
} | |
var apiUrl = "https://api.github.com/users/" + username + "/repos?per_page=1000"; | |
var response = UrlFetchApp.fetch(apiUrl); | |
var data = JSON.parse(response.getContentText()); | |
var maxStars = 0; | |
data.forEach(function(repo) { | |
if (repo.stargazers_count > maxStars) { | |
maxStars = repo.stargazers_count; | |
repoUrl = repo.html_url; | |
} | |
}); | |
adjacentCell.setValue(repoUrl); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment