forked from line/line-bot-sdk-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
106 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env zx | ||
|
||
|
||
// Call this script from the parent repository | ||
// This script determines the type of change to the parent repository | ||
// by checking the latest commit message and the status of the submodule. | ||
// The possible change types are: | ||
// - submodule-update: The submodule has been updated. | ||
// - other: The parent repository has been updated, but the submodule has not been updated. | ||
|
||
const submoduleDir = "line-openapi"; | ||
|
||
async function determineChangeType() { | ||
// Get the latest commit message | ||
const { stdout: lastCommit } = await $`git log -1 --pretty=%s`; | ||
|
||
// Get the status of the submodule | ||
const { stdout: submoduleStatus } = await $`git submodule status ${submoduleDir}`; | ||
const hasUpdate = submoduleStatus.trim().startsWith('+'); | ||
|
||
// Determine the type of change | ||
if (lastCommit.includes(submoduleDir)) { | ||
console.log("submodule-update"); | ||
} else if (hasUpdate) { | ||
console.log("submodule-update"); | ||
} else { | ||
console.log("other"); | ||
} | ||
} | ||
|
||
await determineChangeType(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/usr/bin/env zx | ||
|
||
import fs from "fs/promises"; | ||
|
||
const submoduleDir = "line-openapi"; | ||
const repo = "line/line-openapi"; | ||
|
||
// じっさいに、submoduleをつかったレポジトリで試す | ||
|
||
async function generatePrInfo() { | ||
// Submodule ディレクトリに移動 | ||
cd(submoduleDir); | ||
|
||
// Submodule の最新コミットメッセージを取得 | ||
const { stdout: lastCommit } = await $`git log -1 --pretty=%s`; | ||
console.log("Last commit in submodule:", lastCommit.trim()); | ||
|
||
// 最新コミットメッセージから PR 番号 (#数字) を抽出 | ||
const prNumberMatch = lastCommit.match(/#(\d+)/); | ||
if (!prNumberMatch) { | ||
console.error("No PR number found in submodule's latest commit. Exiting."); | ||
process.exit(1); | ||
} | ||
const prNumber = prNumberMatch[1]; | ||
console.log("Detected PR number:", prNumber); | ||
|
||
// PR URL を構築 | ||
const prUrl = `https://github.com/${repo}/pull/${prNumber}`; | ||
console.log("Constructed PR URL:", prUrl); | ||
|
||
// PR 情報を取得 | ||
const prInfo = JSON.parse(await $`gh pr view ${prNumber} --repo ${repo} --json title,body`); | ||
const prTitle = prInfo.title; | ||
const prBody = prInfo.body; | ||
|
||
// 出力用 JSON を生成 | ||
const output = { | ||
url: prUrl, | ||
title: prTitle, | ||
body: prBody, | ||
}; | ||
await fs.writeFile("../pr_info.json", JSON.stringify(output, null, 2)); | ||
console.log("PR information saved to pr_info.json"); | ||
|
||
// 作業ディレクトリを元に戻す | ||
cd(".."); | ||
} | ||
|
||
await generatePrInfo(); |