const axios = require('axios');
const path = require('path');
const { readPropertiesFile, replacePlaceholders } = require('../essential');
async function getReleaseVersion(org, repo, version) {
const filePath = path.join(__dirname, 'properties', 'api.properties');
const config = readPropertiesFile(filePath);
if (!config.reporeleaseurl) {
throw new Error("Release URL is missing in the configuration.");
}
const replacements = { organization: org, repository: repo };
try {
const response = await axios.get(replacePlaceholders(config.reporeleaseurl, replacements));
const release = response.data.find(r => r.tag_name === version);
if (release) {
return { success: true, releaseName: release.name, releaseTag: release.tag_name, releaseURL: release.html_url };
} else {
return { success: false, message: `Release ${version} not found.` };
}
} catch (error) {
console.error('Error fetching GitHub release:', error.message);
return { success: false, message: error.message };
}
}
module.exports = getReleaseVersion;
/*
@param org = String
@param repo = String
@param token = String
*/
const { getReleaseVersion } = require('jwz/github');
const org = 'your-org-name';
const repo = 'your-repo-name';
const version = 'v1.0.0';
const res = await getReleaseVersion(org, repo, version);
console.log(res);
The getReleaseVersion
function is a utility for fetching specific release details from a GitHub repository. It uses Axios for making API requests and supports dynamic URL construction. Here's a breakdown:
org
: The name of the GitHub organization or user that owns the repository.repo
: The name of the repository from which the release details are fetched.version
: The tag name of the release to retrieve (e.g., 'v1.0.0'
).success
: true
releaseName
: Name of the releasereleaseTag
: Tag name of the releasereleaseURL
: URL of the releasesuccess
: false
message
: An error message indicating the release is not found.