Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Commit

Permalink
Use ArtifactFilePathFetcher in changelog:generate command (#426)
Browse files Browse the repository at this point in the history
* Use ArtifactFilePathFetcher in changelog:generate command
  • Loading branch information
aly76 authored Mar 10, 2021
1 parent cb28b3c commit d7fe259
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 24 deletions.
2 changes: 1 addition & 1 deletion packages/sfpowerscripts-cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/sfpowerscripts-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@dxatscale/sfpowerscripts",
"description": "Simple wrappers around sfdx commands to help set up CI/CD quickly",
"version": "3.0.5",
"version": "3.0.6",
"author": "dxatscale",
"bin": {
"readVars": "./scripts/readVars.sh"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { flags, SfdxCommand } from '@salesforce/command';
import { Messages } from '@salesforce/core';
import ArtifactFilePathFetcher, { ArtifactFilePaths } from "@dxatscale/sfpowerscripts.core/lib/artifacts/ArtifactFilePathFetcher";
import PackageMetadata from "@dxatscale/sfpowerscripts.core/lib/PackageMetadata";
import { ReleaseChangelog, Release, Artifact } from "@dxatscale/sfpowerscripts.core/lib/changelog/interfaces/ReleaseChangelogInterfaces";
import { Changelog as PackageChangelog } from "@dxatscale/sfpowerscripts.core/lib/changelog/interfaces/GenericChangelogInterfaces";
Expand All @@ -8,7 +9,6 @@ import * as fs from "fs-extra"
import path = require('path');
import simplegit, { SimpleGit } from "simple-git/promise";
const tmp = require('tmp');
const glob = require("glob");


Messages.importMessagesDirectory(__dirname);
Expand All @@ -19,7 +19,7 @@ export default class GenerateChangelog extends SfdxCommand {
public static description = messages.getMessage('commandDescription');

public static examples = [
`$ sfdx sfpowerscripts:changelog:generate -n <releaseName> -d path/to/artifact/directory -w <regexp> -r <repoURL> -b <branchName> `
`$ sfdx sfpowerscripts:changelog:generate -n <releaseName> -d path/to/artifact/directory -w <regexp> -r <repoURL> -b <branchName>`
];

protected static requiresUsername = false;
Expand Down Expand Up @@ -87,16 +87,11 @@ export default class GenerateChangelog extends SfdxCommand {
git = simplegit(repoTempDir);
await git.checkout(this.flags.branchname);


let packageMetadataFilepaths: string[] = glob.sync(
`**/artifact_metadata.json`,
{
cwd: path.resolve(process.cwd(), this.flags.artifactdir),
absolute: true
}
let artifact_filepaths: ArtifactFilePaths[] = ArtifactFilePathFetcher.fetchArtifactFilePaths(
this.flags.artifactdir
);

if (packageMetadataFilepaths.length === 0) {
if (artifact_filepaths.length === 0) {
throw new Error(`No artifacts found at ${path.resolve(process.cwd(), this.flags.artifactdir)}`);
}

Expand All @@ -109,9 +104,11 @@ export default class GenerateChangelog extends SfdxCommand {

// Read artifacts for latest release definition
let missingChangelogs: Error[] = [];
for (let packageMetadataFilepath of packageMetadataFilepaths ) {
for (let artifactFilepaths of artifact_filepaths ) {

let packageMetadata: PackageMetadata = JSON.parse(fs.readFileSync(packageMetadataFilepath, 'utf8'));
let packageMetadata: PackageMetadata = JSON.parse(
fs.readFileSync(artifactFilepaths.packageMetadataFilePath, 'utf8')
);

let artifact: Artifact = {
name: packageMetadata["package_name"],
Expand All @@ -124,18 +121,13 @@ export default class GenerateChangelog extends SfdxCommand {

latestReleaseDefinition["artifacts"].push(artifact);

let changelogFilepath: string = path.join(
path.dirname(packageMetadataFilepath),
`changelog.json`
);

if (!fs.existsSync(changelogFilepath)) {
if (!fs.existsSync(artifactFilepaths.changelogFilePath)) {
missingChangelogs.push(
new Error(`No changelog found in artifact ${packageMetadata["package_name"]} ${packageMetadata["package_version_number"]}`)
);
}

packageChangelogMap[packageMetadata["package_name"]] = changelogFilepath;
packageChangelogMap[packageMetadata["package_name"]] = artifactFilepaths.changelogFilePath;
}

if (missingChangelogs.length > 0) {
Expand All @@ -159,7 +151,6 @@ export default class GenerateChangelog extends SfdxCommand {
for (let artifact of latestReleaseDefinition["artifacts"]) {
for (let prevReleaseArtifact of prevReleaseDefinition["artifacts"]) {
if (artifact["name"] === prevReleaseArtifact["name"]) {
// Verify that this modifies latestReleaseDefinition
artifact["from"] = prevReleaseArtifact["to"];
prevReleaseLatestCommitId[artifact["name"]] = prevReleaseArtifact["latestCommitId"];
break;
Expand All @@ -170,7 +161,9 @@ export default class GenerateChangelog extends SfdxCommand {

// Get commits for the latest release
for (let artifact of latestReleaseDefinition["artifacts"]) {
let packageChangelog: PackageChangelog = JSON.parse(fs.readFileSync(packageChangelogMap[artifact["name"]], 'utf8'));
let packageChangelog: PackageChangelog = JSON.parse(
fs.readFileSync(packageChangelogMap[artifact["name"]], 'utf8')
);

artifact["latestCommitId"] = packageChangelog["commits"][0]["commitId"];

Expand Down Expand Up @@ -239,7 +232,13 @@ export default class GenerateChangelog extends SfdxCommand {
JSON.stringify(releaseChangelog, null, 4)
);

let payload: string = generateMarkdown(releaseChangelog, this.flags.workitemurl, this.flags.limit, this.flags.showallartifacts);
let payload: string = generateMarkdown(
releaseChangelog,
this.flags.workitemurl,
this.flags.limit,
this.flags.showallartifacts
);

fs.writeFileSync(
path.join(repoTempDir,`Release-Changelog.md`),
payload
Expand Down

0 comments on commit d7fe259

Please sign in to comment.