Skip to content

Instantly share code, notes, and snippets.

@iamwillbar
Created December 14, 2017 22:16
Show Gist options
  • Save iamwillbar/d7a4cb3ae76d72e15f1583db070dc93c to your computer and use it in GitHub Desktop.
Save iamwillbar/d7a4cb3ae76d72e15f1583db070dc93c to your computer and use it in GitHub Desktop.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
const ghrequestor = require('ghrequestor');
function discoverRefFromGitHub(id, version, licenseStore, sourceRepositoryUrl, gitHubUrl) {
return ghrequestor.getAll(`https://api.github.com/repos/${encodeURIComponent(gitHubUrl.owner)}/${encodeURIComponent(gitHubUrl.name)}/git/refs`, {
headers: {
'User-Agent': 'msftgits/component-metadata-service',
'Authorization': 'token ' + config.get('GITHUB_TOKEN')
},
maxAttempts: 3,
retryDelay: 250,
retryStrategy: request.RetryStrategies.HTTPOrNetworkError,
json: true
}).then(refs => {
if (refs) {
for (let i = 0; i < refs.length; i++) {
const ref = refs[i];
if (ref.ref.endsWith(`/${version}`) || ref.ref.endsWith(`/v${version}`)) {
return ref;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment