Skip to content

Commit

Permalink
Code to get a single "tag" from GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricioszabo committed Jul 4, 2024
1 parent e9ef304 commit c971f82
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/vcs_providers/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,56 @@ class GitHub extends Git {
}
}

async tag(userObj, ownerRepo, tagString) {
try {
const raw = await this._webRequestAuth(
`/repos/${ownerRepo}/commits/${tagString}`,
userObj.token
);

if (!raw.ok) {
if (raw.short === "Failed Request") {
switch (raw.content.status) {
case 401:
return {
ok: false,
short: "Bad Auth",
content: raw.content.status,
};
default:
return {
ok: false,
short: "Server Error",
content: raw.content.status,
};
}
}
return {
ok: false,
short: "Server Error",
content: raw.content.status,
};
}

// We have valid commit, let's "coerce" into a tag.
return {
ok: true,
content: {
name: tagString,
commit: { sha: raw.content.body.sha },
tarball_url: `${this.apiUrl}/repos/${ownerRepo}/tarball/${tagString}`
},
};
} catch (err) {
return {
ok: false,
short: "Server Error",
content: null,
error: err,
};
}
}

/**
* @async
* @function packageJSON
Expand Down

0 comments on commit c971f82

Please sign in to comment.