export async function createPrAndAddToProject()

in packages/dependency-graph-integrator/src/pull-requests.ts [93:155]


export async function createPrAndAddToProject(
	stage: string,
	repoName: string,
	owner: string,
	author: string,
	branch: string,
	prTitle: string,
	prBody: string,
	fileName: string,
	fileContents: string,
	commitMessage: string,
	boardNumber: number,
	admins: string[],
	octokit?: Octokit,
) {
	if (stage === 'PROD') {
		const ghClient = octokit ?? (await stageAwareOctokit(stage));

		const pullRequestResponse = await createPullRequest(ghClient, {
			repoName,
			owner,
			title: prTitle,
			body: prBody,
			branchName: branch,
			changes: [
				{
					commitMessage,
					files: {
						[fileName]: fileContents,
					},
				},
			],
			admins,
		});

		if (pullRequestResponse?.html_url && pullRequestResponse.number) {
			console.log(
				'Pull request successfully created:',
				pullRequestResponse.html_url,
			);

			await requestTeamReview(
				ghClient,
				repoName,
				owner,
				pullRequestResponse.number,
				admins,
			);

			await addPrToProject(stage, repoName, boardNumber, author);
			console.log('Updated project board');
		} else {
			console.log('Pull request not created.');
		}
	} else {
		console.log(`Testing generation of ${fileName} for ${repoName}`);
		console.log(fileContents);
		console.log('Testing PR generation');
		console.log('Title:\n', prTitle);
		console.log('Body:\n', prBody);
	}
	console.log('Done');
}