Last active
June 16, 2022 21:33
-
-
Save AvocadoVenom/8e3cd470317c44694ef5e2fba1436299 to your computer and use it in GitHub Desktop.
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 current branch | |
| * | |
| * Master branch: | |
| * Only commits with 'Fix' git trailer will be involved in changelog entries | |
| * | |
| * Other branch: | |
| * Only commits with 'Changelog' (default value) git trailer will be involved in changelog entries. | |
| * | |
| * Example: node ./gitlab-changelog.js | |
| */ | |
| 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_PROJECT_ACCESS_TOKEN = process.env.VITE_GITLAB_PROJECT_ACCESS_TOKEN; | |
| const GITLAB_PROJECT_CHANGELOG_API = process.env.VITE_GITLAB_PROJECT_CHANGELOG_API; | |
| const headers = { | |
| ['Content-Type']: 'application/json', | |
| ['PRIVATE-TOKEN']: GITLAB_PROJECT_ACCESS_TOKEN | |
| }; | |
| // Get current branch name | |
| exec('git rev-parse --abbrev-ref HEAD', async (err, branchName) => { | |
| if(err) onError(err); | |
| const branch = branchName.trim(); | |
| const outputMessage = `Changelog updated: https://gitlab.com/<project-path>/-/blob/${branch}/CHANGELOG.md`; | |
| const trailer = branch === 'master' ? 'Fix' : 'Changelog' | |
| try { | |
| const response = await axios.post(GITLAB_PROJECT_CHANGELOG_API, { version, branch, trailer }, { headers }) | |
| if (response.status === 200) console.log(outputMessage); | |
| } catch (err) { | |
| throw new Error(err) | |
| } | |
| }); | |
| const onError = (err) => { | |
| console.error(err); | |
| return 1; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment