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