@@ -7,9 +7,9 @@ const VERSION = process.env.VERSION;
77const GITHUB_TOKEN = process . env . GITHUB_TOKEN ;
88const PAT = process . env . PAT || GITHUB_TOKEN ;
99const REPO_OWNER = "MendixMobile" ;
10- const REPO_NAME = "MendixMobile " ;
11- // const REPO_NAME = "docs ";
12- const UPSTREAM_OWNER = "mendix" ;
10+ const REPO_NAME = "docs " ;
11+ const UPSTREAM_OWNER = "MendixMobile " ;
12+ // const UPSTREAM_OWNER = "mendix";
1313const BRANCH_NAME = `update-mobile-release-notes-v${ VERSION } ` ;
1414const TARGET_FILE =
1515 "content/en/docs/releasenotes/mobile/make-it-native-parent/make-it-native-10.md" ;
@@ -72,6 +72,28 @@ async function createRelease(unreleasedContent) {
7272 } ) ;
7373}
7474
75+ async function prChangelogUpdate ( ) {
76+ const git = simpleGit ( ) ;
77+
78+ await git . checkoutLocalBranch ( CHANGELOG_BRANCH ) ;
79+
80+ await git . add ( "CHANGELOG.md" ) ;
81+ await git . commit ( `chore: update CHANGELOG for v${ VERSION } ` ) ;
82+ await git . push ( "origin" , CHANGELOG_BRANCH , [ "--force" ] ) ;
83+
84+ await octokit . pulls . create ( {
85+ owner : MAKE_IT_NATIVE_OWNER ,
86+ repo : MAKE_IT_NATIVE_REPO ,
87+ title : `Update CHANGELOG for v${ VERSION } ` ,
88+ head : CHANGELOG_BRANCH ,
89+ base : "development" ,
90+ body : "**Note:** Please do not take any action on this pull request unless it has been reviewed and approved by a member of the Mobile team." ,
91+ draft : true ,
92+ } ) ;
93+
94+ process . chdir ( ".." ) ;
95+ }
96+
7597async function updateDocs ( unreleasedContent ) {
7698 const git = simpleGit ( ) ;
7799 await git . clone (
@@ -80,9 +102,23 @@ async function updateDocs(unreleasedContent) {
80102 process . chdir ( REPO_NAME ) ;
81103 await git . checkoutLocalBranch ( BRANCH_NAME ) ;
82104
83- const fileContent = fs . readFileSync ( TARGET_FILE , "utf-8" ) ;
84- const newContent = `## Make It Native Update\n\n${ unreleasedContent } \n\n${ fileContent } ` ;
85- fs . writeFileSync ( TARGET_FILE , newContent , "utf-8" ) ;
105+ function injectUnreleasedToDoc ( docPath , unreleasedContent ) {
106+ const doc = fs . readFileSync ( docPath , "utf-8" ) ;
107+ const frontmatterMatch = doc . match ( / ^ - - - [ \s \S ] * ?- - - / ) ;
108+ if ( ! frontmatterMatch ) throw new Error ( "Frontmatter not found!" ) ;
109+ const frontmatter = frontmatterMatch [ 0 ] ;
110+ const rest = doc . slice ( frontmatter . length ) . trimStart ( ) ;
111+
112+ const firstParagraphMatch = rest . match ( / ^ ( .* ?\n ) ( \s * \n ) / s) ;
113+ if ( ! firstParagraphMatch ) throw new Error ( "First paragraph not found!" ) ;
114+ const firstParagraph = firstParagraphMatch [ 1 ] ;
115+ const afterFirstParagraph = rest . slice ( firstParagraph . length ) . trimStart ( ) ;
116+
117+ return `${ frontmatter } \n\n${ firstParagraph } \n${ unreleasedContent } \n\n${ afterFirstParagraph } ` ;
118+ }
119+
120+ const newDocContent = injectUnreleasedToDoc ( TARGET_FILE , unreleasedContent ) ;
121+ fs . writeFileSync ( TARGET_FILE , newDocContent , "utf-8" ) ;
86122
87123 await git . add ( TARGET_FILE ) ;
88124 await git . commit ( `docs: update mobile release notes for v${ VERSION } ` ) ;
@@ -107,13 +143,16 @@ This pull request was automatically generated by an automation process managed b
107143 body : prBody ,
108144 draft : true ,
109145 } ) ;
146+
147+ process . chdir ( ".." ) ;
110148}
111149
112150( async ( ) => {
113151 const { changelog, unreleasedContent, changelogPath } = extractUnreleased ( ) ;
114152
115153 await createRelease ( unreleasedContent ) ;
116154 updateChangelog ( { changelog, unreleasedContent, changelogPath } ) ;
155+ await prChangelogUpdate ( ) ;
117156 await updateDocs ( unreleasedContent ) ;
118157
119158 console . log ( "Release, changelog update, and docs PR completed!" ) ;
0 commit comments