Created
December 14, 2017 22:16
-
-
Save iamwillbar/d7a4cb3ae76d72e15f1583db070dc93c 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
// 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