Skip to content

Commit

Permalink
Cleanup @changesets/git tests (#1029)
Browse files Browse the repository at this point in the history
* Cleanup `@changesets/git` tests

* Add `short` option to `getCommitsThatAddFiles`

* Remove unused `deprecate`

* Remove last occurence of `getCommitThatAddsFile`

* add changesets
  • Loading branch information
Andarist authored Dec 14, 2022
1 parent e02a0c4 commit 598136a
Show file tree
Hide file tree
Showing 8 changed files with 351 additions and 228 deletions.
10 changes: 10 additions & 0 deletions .changeset/beige-pans-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@changesets/git": major
---

`getCommitsThatAddFiles` accepts an options object argument now where you can use `cwd` option.

```diff
-getCommitsThatAddFiles(paths, cwd);
+getCommitsThatAddFiles(paths, { cwd });
```
5 changes: 5 additions & 0 deletions .changeset/serious-candles-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@changesets/git": major
---

`getCurrentCommitId` and `getCommitsThatAddFiles` return full commit hashes now instead of short ones. You can get short ones by using the `short: true` option.
5 changes: 5 additions & 0 deletions .changeset/soft-apes-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@changesets/git": major
---

Previously deprecated `getCommitThatAddsFile` has been removed while `getCommitsThatAddFiles` is still available.
10 changes: 5 additions & 5 deletions packages/apply-release-plan/src/index.ts
Original file line number Diff line number Diff line change
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);
const commits = await git.getCommitsThatAddFiles(paths, { cwd, short: true });

if (commits.every(stringDefined)) {
// We have commits for all files
Expand All @@ -51,10 +51,10 @@ async function getCommitsThatAddChangesets(
.filter(stringDefined);

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

// Fill in the blanks in the array of commits
changesetIds.forEach((id, i) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable import/no-extraneous-dependencies */
import startCase from "lodash.startcase";
import { getCommitThatAddsFile } from "@changesets/git";
import { getCommitsThatAddFiles } from "@changesets/git";
import { ComprehensiveRelease, NewChangeset } from "@changesets/types";

import { RelevantChangesets } from "../types";
Expand All @@ -10,9 +10,9 @@ async function getReleaseLine(changeset: NewChangeset, cwd: string) {
.split("\n")
.map((l) => l.trimRight());

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

return `- [${commitThatAddsFile}] ${firstLine}\n${futureLines
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/version/index.ts
Original file line number Diff line number Diff line change
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 })
? await getCurrentCommitId({ cwd, short: true })
: undefined,
}
: undefined
Expand Down
Loading

0 comments on commit 598136a

Please sign in to comment.