/[osn-commons]/trunk/git/genchangelog
ViewVC logotype

Diff of /trunk/git/genchangelog

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 53 by rakinar2, Thu Aug 8 18:23:21 2024 UTC revision 54 by rakinar2, Thu Aug 29 06:17:33 2024 UTC
# Line 163  function parseGitLog(gitLog) { Line 163  function parseGitLog(gitLog) {
163      return commits;      return commits;
164  }  }
165    
166    function generateMarkdownChangelog(commits) {
167        let output = "# Changelog\n\n";
168    
169        const grouppedCommitsByDate = {};
170    
171        for (const commit of commits) {
172            const key = `${commit.createdAt
173                .getUTCDate()
174                .toString()
175                .padStart(2, 0)}-${(commit.createdAt.getUTCMonth() + 1)
176                .toString()
177                .padStart(2, "0")}-${commit.createdAt.getUTCFullYear()}::${
178                Array.isArray(commit.author)
179                    ? commit.author.join(":")
180                    : commit.author
181            }`;
182            grouppedCommitsByDate[key] ??= [];
183            grouppedCommitsByDate[key].push(commit);
184        }
185    
186        for (const key in grouppedCommitsByDate) {
187            const [date, author] = key.split("::");
188            output += `### ${date} [${author}]\n\n`;
189    
190            for (const commit of grouppedCommitsByDate[key]) {
191                const newLineIndex = commit.message.indexOf("\n");
192                output += `* ${commit.message.slice(0, newLineIndex === -1 ? undefined : newLineIndex)}\n`;
193            }
194    
195            output += "\n";
196        }
197    
198        return output;
199    }
200    
201  function generateChangelog(commits) {  function generateChangelog(commits) {
202      let output = "";      let output = "";
203    
# Line 213  function printHelp() { Line 248  function printHelp() {
248      console.log("Options:");      console.log("Options:");
249      console.log("  -h, --help           Show this help and exit.");      console.log("  -h, --help           Show this help and exit.");
250      console.log("  -v, --version        Show this script's version.");      console.log("  -v, --version        Show this script's version.");
251      console.log("  -o, --output=[FILE]  Write the generated changelog to");      console.log("  -f, --format=        Set the changelog format.");
252        console.log("                       Supported formats are: plain,");
253        console.log("                       markdown.");
254        console.log("  -o, --output=<FILE>  Write the generated changelog to");
255      console.log("                       a file instead of standard output.");      console.log("                       a file instead of standard output.");
256      console.log("      --no-overwrite   Disallow overwriting of the output");      console.log("      --no-overwrite   Disallow overwriting of the output");
257      console.log("                       file if it exists already.");      console.log("                       file if it exists already.");
# Line 259  async function main() { Line 297  async function main() {
297                  "no-overwrite": {                  "no-overwrite": {
298                      type: "boolean",                      type: "boolean",
299                  },                  },
300                    format: {
301                        type: "string",
302                        short: "f"
303                    }
304              },              },
305          }).values;          }).values;
306      } catch (error) {      } catch (error) {
# Line 276  async function main() { Line 318  async function main() {
318          exit(0);          exit(0);
319      }      }
320    
321        if (options.format && !["markdown", "plain"].includes(options.format)) {
322            perror("option `--format` or `-f` only accepts one of the following: markdown, plain");
323            exit(1);
324        }
325    
326      if (!options.output && options["no-overwrite"]) {      if (!options.output && options["no-overwrite"]) {
327          perror(          perror(
328              "option `--no-overwrite' without `--output` does not make sense"              "option `--no-overwrite' without `--output` does not make sense"
# Line 301  async function main() { Line 348  async function main() {
348                  commit.message                  commit.message
349              )              )
350      );      );
351      const changelog = generateChangelog(filteredCommits);      const changelog = options.format === "markdown" ? generateMarkdownChangelog(filteredCommits) : generateChangelog(filteredCommits);
352    
353      if (options.output) {      if (options.output) {
354          try {          try {

Legend:
Removed from v.53  
changed lines
  Added in v.54

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26