Skip to content

Commit

Permalink
Avoid using short commit IDs (#1236)
Browse files Browse the repository at this point in the history
* Avoid using short commit IDs

* Add changeset

* Use short commit IDs in human-readable output
  • Loading branch information
camertron committed Nov 27, 2023
1 parent 0c8829b commit dfd4cca
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .changeset/thin-pumas-remember.md
@@ -0,0 +1,6 @@
---
"@changesets/apply-release-plan": minor
"@changesets/cli": minor
---

Avoid using short commit IDs
5 changes: 2 additions & 3 deletions packages/apply-release-plan/src/index.ts
Expand Up @@ -38,7 +38,7 @@ async function getCommitsThatAddChangesets(
cwd: string
) {
const paths = changesetIds.map((id) => `.changeset/${id}.md`);
const commits = await git.getCommitsThatAddFiles(paths, { cwd, short: true });
const commits = await git.getCommitsThatAddFiles(paths, { cwd });

if (commits.every(stringDefined)) {
// We have commits for all files
Expand All @@ -52,8 +52,7 @@ async function getCommitsThatAddChangesets(

const legacyPaths = missingIds.map((id) => `.changeset/${id}/changes.json`);
const commitsForLegacyPaths = await git.getCommitsThatAddFiles(legacyPaths, {
cwd,
short: true,
cwd
});

// Fill in the blanks in the array of commits
Expand Down
Expand Up @@ -12,7 +12,7 @@ async function getReleaseLine(changeset: NewChangeset, cwd: string) {

const [commitThatAddsFile] = await getCommitsThatAddFiles(
[`.changeset/${changeset.id}.md`],
{ cwd, short: true }
{ cwd }
);

return `- [${commitThatAddsFile}] ${firstLine}\n${futureLines
Expand Down
4 changes: 2 additions & 2 deletions packages/changelog-git/src/index.ts
Expand Up @@ -14,7 +14,7 @@ const getReleaseLine = async (
.map((l) => l.trimRight());

let returnVal = `- ${
changeset.commit ? `${changeset.commit}: ` : ""
changeset.commit ? `${changeset.commit.slice(0, 7)}: ` : ""
}${firstLine}`;

if (futureLines.length > 0) {
Expand All @@ -33,7 +33,7 @@ const getDependencyReleaseLine = async (
const changesetLinks = changesets.map(
(changeset) =>
`- Updated dependencies${
changeset.commit ? ` [${changeset.commit}]` : ""
changeset.commit ? ` [${changeset.commit.slice(0, 7)}]` : ""
}`
);

Expand Down
3 changes: 2 additions & 1 deletion packages/changelog-github/src/index.ts
Expand Up @@ -78,9 +78,10 @@ const changelogFunctions: ChangelogFunctions = {
pull: prFromSummary,
});
if (commitFromSummary) {
const shortCommitId = commitFromSummary.slice(0, 7);
links = {
...links,
commit: `[\`${commitFromSummary}\`](https://github.com/${options.repo}/commit/${commitFromSummary})`,
commit: `[\`${shortCommitId}\`](https://github.com/${options.repo}/commit/${commitFromSummary})`,
};
}
return links;
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/version/index.ts
Expand Up @@ -75,7 +75,7 @@ export default async function version(
? {
tag: options.snapshot === true ? undefined : options.snapshot,
commit: config.snapshot.prereleaseTemplate?.includes("{commit}")
? await getCurrentCommitId({ cwd, short: true })
? await getCurrentCommitId({ cwd })
: undefined,
}
: undefined
Expand Down
4 changes: 2 additions & 2 deletions packages/get-github-info/src/index.ts
Expand Up @@ -208,7 +208,7 @@ export async function getInfo(request: {
user: user ? user.login : null,
pull: associatedPullRequest ? associatedPullRequest.number : null,
links: {
commit: `[\`${request.commit}\`](${data.commitUrl})`,
commit: `[\`${request.commit.slice(0, 7)}\`](${data.commitUrl})`,
pull: associatedPullRequest
? `[#${associatedPullRequest.number}](${associatedPullRequest.url})`
: null,
Expand Down Expand Up @@ -255,7 +255,7 @@ export async function getInfoFromPullRequest(request: {
commit: commit ? commit.abbreviatedOid : null,
links: {
commit: commit
? `[\`${commit.abbreviatedOid}\`](${commit.commitUrl})`
? `[\`${commit.abbreviatedOid.slice(0, 7)}\`](${commit.commitUrl})`
: null,
pull: `[#${request.pull}](https://github.com/${request.repo}/pull/${request.pull})`,
user: user ? `[@${user.login}](${user.url})` : null,
Expand Down

0 comments on commit dfd4cca

Please sign in to comment.