|
| 1 | +#!/usr/bin/env zx |
| 2 | + |
| 3 | +import fs from "fs/promises"; |
| 4 | + |
| 5 | + |
| 6 | +// Call this script from the parent repository |
| 7 | +// This script generates a JSON file containing information about the latest PR |
| 8 | +// that updated the submodule. |
| 9 | +// The JSON file contains the following information: |
| 10 | +// - url: The URL of the PR. |
| 11 | +// - title: The title of the PR. |
| 12 | +// - body: The body of the PR. |
| 13 | +// The JSON file is saved as pr_info.json in the parent repository. |
| 14 | + |
| 15 | +const submoduleDir = "line-openapi"; |
| 16 | +const repo = "line/line-openapi"; |
| 17 | + |
| 18 | +async function generatePrInfo() { |
| 19 | + // Change to the submodule directory |
| 20 | + cd(submoduleDir); |
| 21 | + |
| 22 | + // Get the latest commit message in the submodule |
| 23 | + const { stdout: lastCommit } = await $`git log -1 --pretty=%s`; |
| 24 | + console.log("Last commit in submodule:", lastCommit.trim()); |
| 25 | + |
| 26 | + // Extract the PR number from the commit message |
| 27 | + const prNumberMatch = lastCommit.match(/#(\d+)/); |
| 28 | + if (!prNumberMatch) { |
| 29 | + console.error("No PR number found in submodule's latest commit. Exiting."); |
| 30 | + process.exit(1); |
| 31 | + } |
| 32 | + const prNumber = prNumberMatch[1]; |
| 33 | + console.log("Detected PR number:", prNumber); |
| 34 | + |
| 35 | + const prUrl = `https://github.com/${repo}/pull/${prNumber}`; |
| 36 | + console.log("Constructed PR URL:", prUrl); |
| 37 | + |
| 38 | + // Get the PR title and body |
| 39 | + const prInfo = JSON.parse(await $`gh pr view ${prNumber} --repo ${repo} --json title,body`); |
| 40 | + const prTitle = prInfo.title; |
| 41 | + const prBody = prInfo.body; |
| 42 | + |
| 43 | + // Save the PR information to a JSON file |
| 44 | + const output = { |
| 45 | + url: prUrl, |
| 46 | + title: prTitle, |
| 47 | + body: prBody, |
| 48 | + }; |
| 49 | + await fs.writeFile("../pr_info.json", JSON.stringify(output, null, 2)); |
| 50 | + console.log("PR information saved to pr_info.json"); |
| 51 | + |
| 52 | + // Return to the parent directory |
| 53 | + cd(".."); |
| 54 | +} |
| 55 | + |
| 56 | +await generatePrInfo(); |
0 commit comments