@@ -42,62 +42,13 @@ jobs:
42
42
uses : actions/github-script@v5
43
43
with :
44
44
script : |
45
- const fs = require('fs');
46
- const pr_number = context.issue.number;
47
- const marker = '## Samples Checklist';
48
-
49
- let checklist;
50
- let error = false;
51
-
45
+ const script = require('./scripts/add-checklist-to-pr.js');
52
46
try {
53
- // Read the checklist from the file
54
- checklist = fs.readFileSync('checklist.txt', 'utf8');
55
- checklist = checklist.trim();
56
- if(!checklist) {
57
- checklist = "✅ All good!"
58
- }
59
- else {
60
- error = true;
61
- }
62
- } catch (readFileError) {
63
- throw new Error("Could not read samples checklist from file. Please fix the issues and try again.")
64
- }
65
-
66
- try {
67
- // Get the current PR
68
- const { data: pullRequest } = await github.rest.pulls.get({
69
- owner: context.repo.owner,
70
- repo: context.repo.repo,
71
- pull_number: pr_number
72
- });
73
-
74
- let newBody;
75
- const body = pullRequest.body || "";
76
- const markerIndex = body.indexOf(marker);
77
-
78
- if (markerIndex !== -1) {
79
- // Replace the content below the marker
80
- newBody = body.substring(0, markerIndex + marker.length) + "\n" + checklist;
81
- } else {
82
- // Append the checklist if the marker doesn't exist
83
- newBody = body + "\n" + marker + "\n" + checklist;
84
- }
85
-
86
- // Update the PR description
87
- await github.rest.pulls.update({
88
- owner: context.repo.owner,
89
- repo: context.repo.repo,
90
- pull_number: pr_number,
91
- body: newBody
92
- });
93
- } catch (updatePrError) {
94
- throw new Error("Could not update PR description based on samples checklist. Please fix the issues and try again.")
95
- }
96
-
97
- if (error) {
98
- throw new Error("Incomplete samples checklist. Please fix the issues and try again.");
47
+ await script({github, context});
48
+ core.info(`Checklist successfully added to PR description`);
49
+ } catch (error) {
50
+ core.setFailed(`Script execution failed: ${error.message}`);
99
51
}
100
-
101
52
102
53
- name : Create / Update Template Repo
103
54
uses : actions/github-script@v7
0 commit comments