Skip to content

Instantly share code, notes, and snippets.

@AvocadoVenom
Created May 23, 2022 07:47
Show Gist options
  • Select an option

  • Save AvocadoVenom/a2812ae70698f10ff80ceb6dc9c8c522 to your computer and use it in GitHub Desktop.

Select an option

Save AvocadoVenom/a2812ae70698f10ff80ceb6dc9c8c522 to your computer and use it in GitHub Desktop.
Generates remotely the changelog for the current branch
/* Gets the last version number of the project and generates remotely the changelog on the current branch */
const { exec } = require('child_process');
const axios = require('axios');
const version = require('../../package.json').version;
// Allow to access the environment variables
require('dotenv').config();
const GITLAB_PERSONAL_ACCESS_TOKEN = process.env.VITE_GITLAB_PERSONAL_ACCESS_TOKEN;
const GITLAB_PROJECT_CHANGELOG_API = process.env.VITE_GITLAB_PROJECT_CHANGELOG_API;
exec('git rev-parse --abbrev-ref HEAD', (err, stdout) => {
if(err) {
console.error(err);
return
}
const branch = stdout.trim();
axios
.post(
GITLAB_PROJECT_CHANGELOG_API,
{ version, branch },
{
headers: {
['Content-Type']: 'application/json',
['PRIVATE-TOKEN']: GITLAB_PERSONAL_ACCESS_TOKEN
}
}
)
.then((response) => {
if (response.status === 200)
console.log(`Changelog has been updated: https://gitlab.com/<project-path>/-/blob/${branch}/CHANGELOG.md`);
})
.catch((err) => {
throw new Error(err);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment