Skip to content

Commit

Permalink
fix: if no PR number, default to auto.remote instead of fetching from…
Browse files Browse the repository at this point in the history
… octokit
  • Loading branch information
hborawski committed Jan 8, 2021
1 parent dbccad4 commit ac02033
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
31 changes: 30 additions & 1 deletion plugins/cocoapods/__tests__/cocoapods.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,13 @@ describe("Cocoapods Plugin", () => {
data: {
head: {
repo: {
clone_url: "https://github.com/intuit/auto.git",
clone_url: "https://github.com/intuit-fork/auto.git",
},
},
},
}),
},
remote: "https://github.com/intuit/auto.git",
getCurrentVersion: async () => "0.0.1",
} as unknown) as Auto.Auto);
});
Expand Down Expand Up @@ -399,6 +400,34 @@ describe("Cocoapods Plugin", () => {
expect(exec).toBeCalledTimes(3);
expect(exec).toHaveBeenCalledWith("git", ["checkout", "./Test.podspec"]);

expect(mock).toHaveBeenLastCalledWith(
expect.any(String),
specWithVersion(
"0.1.0-canary.1.1.1",
"{ :git => 'https://github.com/intuit-fork/auto.git', :commit => 'undefined' }"
)
);
});
test("should tag with canary version with no PR number", async () => {
let podSpec = specWithVersion("0.0.1");
jest
.spyOn(utilities, "getPodspecContents")
.mockImplementation(() => podSpec);
const mock = jest
.spyOn(utilities, "writePodspecContents")
.mockImplementation((path, contents) => {
podSpec = contents;
});

const newVersion = await hooks.canary.promise({
bump: "minor" as Auto.SEMVER,
canaryIdentifier: "canary.1.1.1",
});

expect(newVersion).toBe("0.1.0-canary.1.1.1");
expect(exec).toBeCalledTimes(3);
expect(exec).toHaveBeenCalledWith("git", ["checkout", "./Test.podspec"]);

expect(mock).toHaveBeenLastCalledWith(
expect.any(String),
specWithVersion(
Expand Down
17 changes: 13 additions & 4 deletions plugins/cocoapods/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,23 @@ export default class CocoapodsPlugin implements IPlugin {
auto.hooks.canary.tapPromise(
this.name,
async ({ bump, canaryIdentifier, dryRun, quiet }) => {
if (!auto.git) {
return;
}

const pr = getPrNumberFromEnv();

if (!auto.git || !pr) {
return;
if (!pr) {
this.logger?.log.info(
logMessage(
`No PR number found, using ${auto.remote} as the remote for canary. Commit must be pushed for this to work.`
)
);
}

const remoteRepo = await (await auto.git.getPullRequest(pr)).data.head
.repo.clone_url;
const remoteRepo = pr
? await (await auto.git.getPullRequest(pr)).data.head.repo.clone_url
: auto.remote;

const lastRelease = await auto.git.getLatestRelease();
const current = await auto.getCurrentVersion(lastRelease);
Expand Down

0 comments on commit ac02033

Please sign in to comment.