Skip to content

Commit

Permalink
Merge branch 'main' into migration
Browse files Browse the repository at this point in the history
  • Loading branch information
tianzhou committed Mar 14, 2024
2 parents 02e268f + b6fa77a commit 25e89c6
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 54 deletions.
58 changes: 32 additions & 26 deletions .github/actions/upsert-issue/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,9 @@ function generateChangeIdAndSchemaVersion(repo, pr, file) {
return { id: `ch-${repo}-pr${pr}-${version}`.replace(/[^a-zA-Z0-9]/g, '-'), version };
}
function run() {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const githubToken = core.getInput('github-token', { required: true });
const pattern = core.getInput('pattern', { required: true });
const octokit = github.getOctokit(githubToken);
const url = core.getInput("url", { required: true });
const token = core.getInput("token", { required: true });
const projectId = core.getInput("project-id", { required: true });
Expand All @@ -72,6 +70,37 @@ function run() {
headers = extraHeaders ? JSON.parse(extraHeaders) : {};
headers = Object.assign({ "Content-Type": "application/json", 'Authorization': `Bearer ${token}` }, headers);
projectUrl = `${url}/v1/projects/${projectId}`;
const changes = yield collectChanges(githubToken, database, pattern);
let issue = yield findIssue(title);
// If found existing issue, then update if migration script changes.
// Otherwise, create a new issue.
if (issue) {
if (issue.plan) {
updateIssuePlan(issue, changes, title);
}
else {
// In theory, every issue must have a plan, otherwise issue creation will return error:
// {"code":3, "message":"plan is required", "details":[]}
throw new Error('Missing plan from the existing issue.');
}
}
else {
// Create plan
let plan = yield createPlan(changes, title, description);
// Create issue
issue = yield createIssue(plan.name, assignee, title, description);
// Create rollout
yield createRollout(plan.name);
const issueURL = `${projectUrl}/issues/${issue.uid}`;
core.info("Successfully created issue at " + issueURL);
}
});
}
run();
function collectChanges(githubToken, database, pattern) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const octokit = github.getOctokit(githubToken);
const githubContext = github.context;
const { owner, repo } = githubContext.repo;
const prNumber = (_a = githubContext.payload.pull_request) === null || _a === void 0 ? void 0 : _a.number;
Expand Down Expand Up @@ -111,32 +140,9 @@ function run() {
schemaVersion: version,
});
}
let issue = yield findIssue(title);
// If found existing issue, then update if migration script changes.
// Otherwise, create a new issue.
if (issue) {
if (issue.plan) {
updateIssuePlan(issue, changes, title);
}
else {
// In theory, every issue must have a plan, otherwise issue creation will return error:
// {"code":3, "message":"plan is required", "details":[]}
throw new Error('Missing plan from the existing issue.');
}
}
else {
// Create plan
let plan = yield createPlan(changes, title, description);
// Create issue
issue = yield createIssue(plan.name, assignee, title, description);
// Create rollout
yield createRollout(plan.name);
const issueURL = `${url}/projects/${projectId}/issues/${issue.uid}`;
core.info("Successfully created issue at " + issueURL);
}
return changes;
});
}
run();
function createPlan(changes, title, description) {
return __awaiter(this, void 0, void 0, function* () {
try {
Expand Down
61 changes: 33 additions & 28 deletions .github/actions/upsert-issue/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ function generateChangeIdAndSchemaVersion(repo: string, pr: string, file: string
async function run(): Promise<void> {
const githubToken = core.getInput('github-token', { required: true });
const pattern = core.getInput('pattern', { required: true });
const octokit = github.getOctokit(githubToken);
const url = core.getInput("url", { required: true })
const token = core.getInput("token", { required: true })
const projectId = core.getInput("project-id", { required: true })
Expand All @@ -49,6 +48,38 @@ async function run(): Promise<void> {

projectUrl = `${url}/v1/projects/${projectId}`

const changes = await collectChanges(githubToken, database, pattern);

let issue = await findIssue(title);
// If found existing issue, then update if migration script changes.
// Otherwise, create a new issue.
if (issue) {
if (issue.plan) {
updateIssuePlan(issue, changes, title)
} else {
// In theory, every issue must have a plan, otherwise issue creation will return error:
// {"code":3, "message":"plan is required", "details":[]}
throw new Error('Missing plan from the existing issue.');
}
} else {
// Create plan
let plan = await createPlan(changes, title, description);

// Create issue
issue = await createIssue(plan.name, assignee, title, description);

// Create rollout
await createRollout(plan.name)

const issueURL = `${projectUrl}/issues/${issue.uid}`
core.info("Successfully created issue at " + issueURL)
}
}

run();

async function collectChanges(githubToken: string, database: string, pattern: string) : Promise<Change[]> {
const octokit = github.getOctokit(githubToken);
const githubContext = github.context;
const { owner, repo } = githubContext.repo;
const prNumber = githubContext.payload.pull_request?.number;
Expand Down Expand Up @@ -91,39 +122,13 @@ async function run(): Promise<void> {
database,
file,
content: Buffer.from(content).toString(),

schemaVersion: version,
});
}

let issue = await findIssue(title);
// If found existing issue, then update if migration script changes.
// Otherwise, create a new issue.
if (issue) {
if (issue.plan) {
updateIssuePlan(issue, changes, title)
} else {
// In theory, every issue must have a plan, otherwise issue creation will return error:
// {"code":3, "message":"plan is required", "details":[]}
throw new Error('Missing plan from the existing issue.');
}
} else {
// Create plan
let plan = await createPlan(changes, title, description);

// Create issue
issue = await createIssue(plan.name, assignee, title, description);

// Create rollout
await createRollout(plan.name)

const issueURL = `${url}/projects/${projectId}/issues/${issue.uid}`
core.info("Successfully created issue at " + issueURL)
}
return changes;
}

run();

async function createPlan(changes: Change[], title: string, description: string) : Promise<any> {
try {
// Initialize an empty array for the specs
Expand Down

0 comments on commit 25e89c6

Please sign in to comment.