I am using Github API to return the sha of a branch by branch name. Why is my function returning undefined?
const branches = (b) => {
let theName;
octokit.request(`GET /repos/owner/repo/branches`, {
owner: "owner",
repo: "repo"
}).then(response => {
response.data.forEach(d => {
if (d.name === b) theName = d.commit.sha;
});
});
return theName;
}
console.log(branch('main'));
What am I missing here? How do I get my function to return the value stored in theName.