Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat(*): nouvelle version interne changelog [DS-3230] #590

Merged
merged 6 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .auto-changelog

This file was deleted.

2,484 changes: 1,933 additions & 551 deletions CHANGELOG.md

Large diffs are not rendered by default.

40 changes: 0 additions & 40 deletions changelog-template.hbs

This file was deleted.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"release": "node tool/tool.js release",
"deploy": "node tool/tool.js deploy",
"standalone": "node tool/tool.js standalone",
"serve": "browser-sync start --server --port 8080 --startPath example/",
"version": "auto-changelog -p"
"changelog": "node tool/tool.js changelog",
"serve": "browser-sync start --server --port 8080 --startPath example/"
},
"files": [
"/dist",
Expand All @@ -39,7 +39,6 @@
"@commitlint/config-conventional": "^15.0.0",
"@rollup/plugin-buble": "^0.21.3",
"@rollup/plugin-virtual": "^2.1.0",
"auto-changelog": "^2.4.0",
"browser-sync": "^2.27.10",
"browserslist": "^4.21.5",
"cssnano": "^5.1.15",
Expand All @@ -58,6 +57,7 @@
"js-yaml": "^4.1.0",
"mqpacker": "^7.0.0",
"pa11y": "^6.2.3",
"parse-github-url": "^1.0.2",
"path": "^0.12.7",
"postcss": "^8.4.21",
"postcss-banner": "^4.0.1",
Expand All @@ -72,6 +72,7 @@
"rollup-plugin-terser": "^7.0.2",
"sass": "^1.59.2",
"sass-true": "^6.1.0",
"semver": "^7.5.0",
"standard": "^16.0.4",
"stylelint": "^13.13.1",
"stylelint-config-standard": "^20.0.0",
Expand Down
24 changes: 24 additions & 0 deletions tool/classes/changelog/changelog.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Changelog du Système de design de l’État

Toutes les modifications notables apportées à ce projet sont documentées dans ce fichier.

Le format est basé sur [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
et ce projet respecte [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

Pour plus d’informations : [Voir la documentation](https://www.systeme-de-design.gouv.fr/)

<% for (const major of locals.majors) { %>
> ## <%= major.title %>
<% for (const minor of major.minors) { %>
## <%= minor.title %>
<% for (const tag of minor.tags) { %>
### [<%= tag.tag %>](<%= tag.href %>) - <%- tag.niceDate %>
<% for (const commit of tag.commits) { %>
#### <%= commit.subject %><% if (commit.jira) { %> [<%- commit.jira %>]<% } %><% if (commit.href) { %> [(#<%= commit.id %>)](<%= commit.href %>)<% } %>
<% if (commit.details) { %><%= commit.details %>
<% } %>
<% } %>
<% } %>
<% } %>
---
<% } %>
31 changes: 31 additions & 0 deletions tool/classes/changelog/changelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const { Tags } = require('./tag');
const ejs = require('ejs');
const root = require('../../utilities/root');
const { html: beautify } = require('js-beautify');
const { createFile } = require('../../utilities/file');
const log = require('../../utilities/log');

class Changelog {
constructor (current) {
this._current = current;
}

async build () {
this.tags = new Tags(this._current);
await this.tags.load();

const data = { majors: this.tags.majors };

ejs.renderFile(root('tool/classes/changelog/changelog.ejs'), data
, (error, str) => {
if (error) {
console.log(error);
} else {
createFile(root('CHANGELOG.md'), str, true);
log(38, 'CHANGELOG.md');
}
});
}
}

module.exports = { Changelog };
71 changes: 71 additions & 0 deletions tool/classes/changelog/commit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const { cmd, gitmoji } = require('./utils');
const { remote } = require('./remote');
const log = require('../../utilities/log');

class Commit {
constructor (sha) {
this._sha = sha;
}

get subject () {
return this._subject;
}

get details () {
return this._details;
}

get id () {
return this._id;
}

get href () {
return this._href;
}

get jira () {
return false; // this._jira;
}

get isValid () {
return this._isValid;
}

async load () {
const gitLog = await cmd(`git log --format=%B -n 1 ${this._sha}`);
const lines = gitLog.split('\n');
const subject = lines[0].trim();
const regex = /\(#(\d+)\)/;
const id = subject.match(regex);
if (Array.isArray(id) && id.length >= 2) {
this._id = id[1];
this._href = remote.pull(this._id);
}
const idsRegex = /DS-\d+/g;
const ids = subject.match(idsRegex);
if (Array.isArray(ids) && ids.length > 0) {
this._jira = ids.map(id => `[${id}](<https://gouvfr.atlassian.net/browse/${id}>)`).join(',');
}

this._subject = gitmoji(subject.replace(regex, '').replace(/\[DS-[DS-\d, ]+]/g, '').trim());
this._details = lines.slice(1).join('\n').trim();
this._details = this._details.replace(/^#{1,6}\s/g, '').replace(/\n#{1,6}\s/g, '');

switch (true) {
case this._subject.match(/chore.+DSFR/) !== null:
case this._subject.match(/chore.+changelog/) !== null:
case this._subject.match(/chore.+incrémentation/) !== null:
case this._subject.match(/chore.+incémentation/) !== null:
lab9fr marked this conversation as resolved.
Show resolved Hide resolved
case this._subject.match(/^((..|.|(:\w+:))\s*)?(build|chore|ci|doc|docs|feat|feature|fix|perf|refactor|revert|style|test)(\(.*\))?/i) === null:
this._isValid = false;
log.error(this._subject, true);
break;

default:
this._isValid = true;
log.info(this._subject, true);
}
}
}

module.exports = { Commit };
25 changes: 25 additions & 0 deletions tool/classes/changelog/remote.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const { cmd } = require('./utils');
const parseRepoURL = require('parse-github-url');

class Remote {
async load () {
const remoteURL = await cmd('git config --get remote.origin.url');
this.remote = parseRepoURL(remoteURL);
const protocol = this.remote.protocol === 'http:' ? 'http:' : 'https:';
const hostname = this.remote.hostname || this.remote.host;
const repository = this.remote.repo;
this._url = `${protocol}//${hostname}/${repository}`;
}

compare (from, to) {
return `${this._url}/compare/${from}...${to}`;
}

pull (id) {
return `${this._url}/pull/${id}`;
}
}

const remote = new Remote();

module.exports = { remote };
Loading