Skip to content

Instantly share code, notes, and snippets.

@rmkubik
Last active July 30, 2021 16:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmkubik/9898f63e4ace00093b593d16b24d4c52 to your computer and use it in GitHub Desktop.
Save rmkubik/9898f63e4ace00093b593d16b24d4c52 to your computer and use it in GitHub Desktop.
GitHub Account Validation
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