Skip to content

Commit 2f25705

Browse files
committed
chore: parse
1 parent 2caa685 commit 2f25705

File tree

1 file changed

+41
-17
lines changed

1 file changed

+41
-17
lines changed

.github/workflows/comment-diffs.yml

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -212,23 +212,14 @@ jobs:
212212
# echo "[$library_type/$language](https://github.com/${{github.repository}}/compare/$old_version_commit_hash..$new_version_commit_hash)" >> "$output_file"
213213
214214
215-
# Add type to output file
216-
message="""<details>
217-
<summary>${library_type}/${language}</summary>"""
215+
# Add type to output file
216+
echo "${library_type} ${language}" >> $output_file
218217

219-
echo $message >> $output_file
218+
# Add changes to output file
219+
git diff HEAD~ >> $output_file
220220

221-
echo "\`\`\`diff" >> $output_file
222-
echo """${message}""" >> $output_file
223-
echo "\`\`\`" >> $output_file
224-
225-
# Add changes to output file
226-
git diff HEAD~ >> $output_file
227-
228-
echo "</details>" >> $output_file
229-
230-
# Add empty line
231-
echo \ >> $output_file
221+
# Add empty line
222+
echo \ >> $output_file
232223
fi
233224
}
234225

@@ -292,11 +283,44 @@ jobs:
292283
with:
293284
github-token: ${{secrets.GITHUB_TOKEN}}
294285
script: |
286+
const replaceTable = {
287+
"module-legacy": "Native module",
288+
"module-mixed": "Turbo module with backward compat",
289+
"module-new": "Turbo module",
290+
"view-legacy": "Native view",
291+
"view-mixed": "Fabric view with backward compat",
292+
"view-new": "Fabric view",
293+
"java-objc": "Java and Objective C",
294+
"java-swift": "Java and Swift",
295+
"kotlin-objc": "Kotlin and Objective C",
296+
"kotlin-swift": "Kotlin and Swift"
297+
}
298+
295299
const artifacts = `${{ steps.artifacts.outputs.ARTIFACTS }}`;
296300
301+
// Get every input by empty line
302+
303+
const splittedArtifacts = artifacts.split("\n\n")
304+
const parsedArtifacts = splittedArtifacts.map((artifact) => {
305+
// The first line indicates the type
306+
const type = artifacts.split("\n").shift()
307+
const typeReplaced = Object.entries(replaceTable).reduce((acc, [key, value]) => {
308+
return acc.replace(new RegExp(key, "g"), value);
309+
}, type)
310+
311+
return `<details>
312+
<summary>${typeReplaced}</summary>
313+
\`\`\`diff
314+
${artifact}
315+
\`\`\`
316+
</details>
317+
318+
`
319+
})
320+
297321
const body = `🤓☝️ This PR changes the output of \`create-react-native-library\`. You can find the diffs of effected templates below:
298322
299-
${artifacts}
323+
${parsedArtifacts}
300324
`;
301325
302326
const comments = await github.issues.listComments({
@@ -313,4 +337,4 @@ jobs:
313337
repo: context.repo.repo,
314338
body
315339
})
316-
340+

0 commit comments

Comments
 (0)