Last active
July 30, 2021 16:39
-
-
Save rmkubik/9898f63e4ace00093b593d16b24d4c52 to your computer and use it in GitHub Desktop.
GitHub Account Validation
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
const got = require('got'); | |
module.exports = async helper => { | |
const username = helper.getNormalizedInput('username', { lowerCase: false }); | |
if (!username) { | |
return helper.fail(`Please enter the username of your GitHub account!`); | |
} | |
try { | |
const response = await got(`https://api.github.com/users/${username}`, { | |
throwHttpErrors: false, | |
}); | |
if (response.statusCode === 200) { | |
return helper.success( | |
`We found your GitHub user, ${username}. Good job!`, | |
[{ name: 'GITHUB_USERNAME', value: username }] | |
); | |
} else { | |
helper.fail( | |
`We couldn't find the GitHub user, ${username}. Is there a typo in the username?` | |
); | |
} | |
} catch (err) { | |
helper.fail( | |
`Something went wrong when we tried to validate your GitHub username! | |
${err}` | |
); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment