Last active
July 7, 2022 00:20
-
-
Save AvocadoVenom/1e9f3d8a2a3c0949f04cf446ea041a2e to your computer and use it in GitHub Desktop.
Script to generate/update CHANGELOG.md using GitLab API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Gets the last version number of the project and generates remotely the changelog on the dev branch via GitLab API. | |
* | |
* Example: node ./gitlab-changelog.js | |
*/ | |
const axios = require('axios'); | |
const version = require('../../package.json').version; | |
const branch = 'dev'; | |
const link = `https://gitlab.com/<project-path>/-/blob/${branch}/CHANGELOG.md`; | |
// Allow to access the environment variables | |
require('dotenv').config(); | |
const GITLAB_PROJECT_ACCESS_TOKEN = process.env.GITLAB_PROJECT_ACCESS_TOKEN; | |
const GITLAB_PROJECT_CHANGELOG_API = process.env.GITLAB_PROJECT_CHANGELOG_API; | |
axios | |
.post( | |
GITLAB_PROJECT_CHANGELOG_API, | |
{ version, branch }, | |
{ | |
headers: { | |
['Content-Type']: 'application/json', | |
['PRIVATE-TOKEN']: GITLAB_PROJECT_ACCESS_TOKEN | |
} | |
} | |
) | |
.then((response) => { | |
if (response.status === 200) console.log(`Updated changelog: ${link}`); | |
}) | |
.catch((err) => { | |
throw new Error(err) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment