Skip to content

Instantly share code, notes, and snippets.

@SourcingDenis
Last active March 13, 2023 20:51
Show Gist options
  • Save SourcingDenis/44ad36e3182e9657ded134557a84035d to your computer and use it in GitHub Desktop.
Save SourcingDenis/44ad36e3182e9657ded134557a84035d to your computer and use it in GitHub Desktop.
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