Skip to content

Commit 013661d

Browse files
Merge branch 'main' into main
2 parents 0658bc8 + 41b85d1 commit 013661d

40 files changed

Lines changed: 471 additions & 139 deletions

.changeset/funny-shoes-scream.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

.changeset/new-buses-carry.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

.changeset/polite-trees-compete.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

.changeset/serious-wasps-unite.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

action/src/flows/pull-request.ts

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -63,42 +63,24 @@ export class PullRequestFlow extends InBranchFlow {
6363
this.ora.start(
6464
`Checking for existing PR with head ${i18nBranchName} and base ${this.platformKit.platformConfig.baseBranchName}`
6565
);
66-
const existingPrNumber = await this.platformKit.getOpenPullRequestNumber({
66+
let prNumber = await this.platformKit.getOpenPullRequestNumber({
6767
branch: i18nBranchName,
6868
});
69-
this.ora.succeed(existingPrNumber ? "PR found" : "No PR found");
7069

71-
if (existingPrNumber) {
72-
// Close existing PR first
73-
this.ora.start(`Closing existing PR ${existingPrNumber}`);
74-
await this.platformKit.closePullRequest({
75-
pullRequestNumber: existingPrNumber,
76-
});
77-
this.ora.succeed(`Closed existing PR ${existingPrNumber}`);
78-
}
79-
80-
// Create new PR
81-
this.ora.start(`Creating new PR`);
82-
const newPrNumber = await this.platformKit.createPullRequest({
83-
head: i18nBranchName,
84-
title: this.platformKit.config.pullRequestTitle,
85-
body: this.getPrBodyContent(),
86-
});
87-
this.ora.succeed(`Created new PR ${newPrNumber}`);
88-
89-
if (existingPrNumber) {
90-
// Post comment about outdated PR
91-
this.ora.start(`Posting comment about outdated PR ${existingPrNumber}`);
92-
await this.platformKit.commentOnPullRequest({
93-
pullRequestNumber: existingPrNumber,
94-
body: `This PR is now outdated. A new version has been created at ${this.platformKit.buildPullRequestUrl(
95-
newPrNumber
96-
)}`,
70+
if (prNumber) {
71+
this.ora.succeed(`Existing PR found: #${prNumber}`);
72+
} else {
73+
// Create new PR
74+
this.ora.start(`Creating new PR`);
75+
prNumber = await this.platformKit.createPullRequest({
76+
head: i18nBranchName,
77+
title: this.platformKit.config.pullRequestTitle,
78+
body: this.getPrBodyContent(),
9779
});
98-
this.ora.succeed(`Posted comment about outdated PR ${existingPrNumber}`);
80+
this.ora.succeed(`Created new PR: #${prNumber}`);
9981
}
10082

101-
return newPrNumber;
83+
return prNumber;
10284
}
10385

10486
private checkoutI18nBranch(i18nBranchName: string) {

action/src/index.ts

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,3 @@
1-
import createOra from "ora";
1+
import main from "./main.js";
22

3-
import { IIntegrationFlow } from "./flows/_base.js";
4-
import { PullRequestFlow } from "./flows/pull-request.js";
5-
import { InBranchFlow } from "./flows/in-branch.js";
6-
import { getPlatformKit } from "./platforms/index.js";
7-
8-
(async function main() {
9-
const ora = createOra();
10-
const platformKit = getPlatformKit();
11-
const { isPullRequestMode } = platformKit.config;
12-
13-
ora.info(`Pull request mode: ${isPullRequestMode ? "on" : "off"}`);
14-
15-
const flow: IIntegrationFlow = isPullRequestMode
16-
? new PullRequestFlow(ora, platformKit)
17-
: new InBranchFlow(ora, platformKit);
18-
19-
const canRun = await flow.preRun?.();
20-
if (canRun === false) {
21-
return;
22-
}
23-
24-
const hasChanges = await flow.run();
25-
if (!hasChanges) {
26-
return;
27-
}
28-
29-
await flow.postRun?.();
30-
})();
3+
main();

action/src/main.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare module "@lingo.dev/_action" {
2+
export default function main(): Promise<void>;
3+
}

action/src/main.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import createOra from "ora";
2+
3+
import { IIntegrationFlow } from "./flows/_base.js";
4+
import { PullRequestFlow } from "./flows/pull-request.js";
5+
import { InBranchFlow } from "./flows/in-branch.js";
6+
import { getPlatformKit } from "./platforms/index.js";
7+
8+
export default async function main() {
9+
const ora = createOra();
10+
const platformKit = getPlatformKit();
11+
const { isPullRequestMode } = platformKit.config;
12+
13+
ora.info(`Pull request mode: ${isPullRequestMode ? "on" : "off"}`);
14+
15+
const flow: IIntegrationFlow = isPullRequestMode
16+
? new PullRequestFlow(ora, platformKit)
17+
: new InBranchFlow(ora, platformKit);
18+
19+
const canRun = await flow.preRun?.();
20+
if (canRun === false) {
21+
return;
22+
}
23+
24+
const hasChanges = await flow.run();
25+
if (!hasChanges) {
26+
return;
27+
}
28+
29+
await flow.postRun?.();
30+
}

action/src/platforms/bitbucket.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ interface BitbucketConfig {
1515
export class BitbucketPlatformKit extends PlatformKit<BitbucketConfig> {
1616
private _bb?: ReturnType<typeof Bitbucket>;
1717

18-
get bb() {
18+
private get bb() {
1919
if (!this._bb) {
2020
this._bb = new Bitbucket({
2121
auth: { token: this.platformConfig.bbToken || "" },

action/src/platforms/github.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Z from "zod";
55
export class GitHubPlatformKit extends PlatformKit {
66
private _octokit?: Octokit;
77

8-
get octokit() {
8+
private get octokit(): Octokit {
99
if (!this._octokit) {
1010
this._octokit = new Octokit({ auth: this.platformConfig.ghToken });
1111
}

0 commit comments

Comments
 (0)