@@ -79,19 +79,19 @@ jobs:
79
79
let prNumber, userTriggering, commentBody;
80
80
81
81
if (eventName === "workflow_dispatch") {
82
- core.info('Running in workflow_dispatch mode');
82
+ core.info('Running in " workflow_dispatch" mode');
83
83
84
- prNumber = ' ${{ github.event.inputs.issue_number }}' ;
85
- userTriggering = ' ${{ github.event.inputs.actor }}' ;
86
- commentBody = ' ${{ github.event.inputs.comment_body }}' ;
87
- commentId = ' ${{ github.event.inputs.comment_id }}' ;
84
+ prNumber = ` ${{ github.event.inputs.issue_number }}` ;
85
+ userTriggering = ` ${{ github.event.inputs.actor }}` ;
86
+ commentBody = ` ${{ github.event.inputs.comment_body }}` ;
87
+ commentId = ` ${{ github.event.inputs.comment_id }}` ;
88
88
} else {
89
- core.info('Running in issue_comment mode');
89
+ core.info('Running in " issue_comment" mode');
90
90
91
- prNumber = ' ${{ github.event.issue.number }}' ;
92
- userTriggering = ' ${{ github.event.comment.user.login }}' ;
93
- commentBody = ' ${{ github.event.comment.body }}' ;
94
- commentId = ' ${{ github.event.comment.id }}' ;
91
+ prNumber = ` ${{ github.event.issue.number }}` ;
92
+ userTriggering = ` ${{ github.event.comment.user.login }}` ;
93
+ commentBody = ` ${{ github.event.comment.body }}` ;
94
+ commentId = ` ${{ github.event.comment.id }}` ;
95
95
}
96
96
core.debug(`PR Number: ${prNumber}`);
97
97
core.debug(`User triggering: ${userTriggering}`);
@@ -275,6 +275,7 @@ jobs:
275
275
core.exportVariable('PR_HEAD_REPO', data.head.repo.full_name);
276
276
core.exportVariable('PR_BASE_BRANCH', `migration/pr-${{ env.PR_NUMBER }}`);
277
277
core.exportVariable('PR_BASE_REPO', data.base.repo.full_name);
278
+
278
279
} else {
279
280
throw new Error('Failed to retrieve pull request details');
280
281
}
@@ -295,20 +296,25 @@ jobs:
295
296
git config --global user.email "${{ secrets.PYANSYS_CI_BOT_EMAIL}}"
296
297
git config pull.rebase true
297
298
298
- echo "Adding ${{ env.PR_HEAD_REPO }} as remote"
299
+ echo "\033[1;92m[INFO] Adding ${{ env.PR_HEAD_REPO }} as remote \033[0m "
299
300
git remote add head_repo https://x-access-token:${{ secrets.PYANSYS_CI_BOT_TOKEN }}@github.com/${{ env.PR_HEAD_REPO }}.git
300
301
301
- echo "Fetching '${{ env.PR_HEAD_BRANCH }}' branch from '${{ env.PR_HEAD_REPO }}'"
302
+ echo "\033[1;92m[INFO] Fetching '${{ env.PR_HEAD_BRANCH }}' branch from '${{ env.PR_HEAD_REPO }}' \033[0m "
302
303
git fetch head_repo ${{ env.PR_HEAD_BRANCH }}
303
- git pull head_repo ${{ env.PR_HEAD_BRANCH }}
304
304
305
- echo "Checking out '${{ env.PR_BASE_BRANCH }}' branch from '${{ env.PR_HEAD_REPO }}/${{ env.PR_HEAD_BRANCH }}'"
305
+ echo "\033[1;92m[INFO] Checking out '${{ env.PR_BASE_BRANCH }}' branch from '${{ env.PR_HEAD_REPO }}/${{ env.PR_HEAD_BRANCH }}' \033[0m "
306
306
git checkout -b ${{ env.PR_BASE_BRANCH }} head_repo/${{ env.PR_HEAD_BRANCH }}
307
307
308
- echo "\033[1;92m[INFO] Merging '${{ env.PR_HEAD_BRANCH }}' branch into '${{ env.PR_BASE_BRANCH }}' \033[0m"
309
- git merge head_repo/${{ env.PR_HEAD_BRANCH }}
308
+ echo "\033[1;92m[INFO] Pulling '${{ env.PR_HEAD_BRANCH }}' from '${{ env.PR_BASE_REPO }}' \033[0m"
309
+ git pull head_repo ${{ env.PR_HEAD_BRANCH }}
310
+
311
+ echo "\033[1;92m[INFO] Merging 'main' branch into '${{ env.PR_BASE_BRANCH }}' \033[0m"
312
+ git merge origin/main
313
+
314
+ # Check for merge conflicts
310
315
CONFLICTS=$(git ls-files -u | wc -l)
311
- echo "CONFLICTS=$CONFLICTS"
316
+ echo "Merge conflicts:"
317
+ echo "${CONFLICTS}"
312
318
313
319
if [[ "$CONFLICTS" -gt 0 && -n "${{ env.MODE }}" ]]; then
314
320
echo "::warning:: Conflicts trying to solve using mode '${{ env.MODE }}'."
@@ -355,6 +361,7 @@ jobs:
355
361
const prHeadRepo = process.env.PR_HEAD_REPO;
356
362
const prBaseBranch = process.env.PR_BASE_BRANCH;
357
363
const prBaseRepo = process.env.PR_BASE_REPO;
364
+ const userTriggering = process.env.USER_TRIGGERING;
358
365
359
366
core.debug(`Listing existing PRs for branch ${prBaseBranch}...`);
360
367
const existingPrs = await github.rest.pulls.list({
@@ -372,20 +379,49 @@ jobs:
372
379
return;
373
380
}
374
381
382
+ // Retrieving the original PR details
383
+ const { originalPR } = await github.rest.pulls.get({
384
+ owner: 'ansys',
385
+ repo: 'pymapdl',
386
+ pull_number: prNumber,
387
+ });
388
+
375
389
// https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#create-a-pull-request
376
390
newPrData = await github.rest.pulls.create({
377
391
owner: 'ansys',
378
392
repo: 'pymapdl',
379
393
debug: true,
380
- head: `${prBaseBranch}`, // This is the branch we just created which becomes now the head of the PR, and the base (target) branch is the main branch.
381
- base: `main`,
382
- title: `chore: migrated PR ${prNumber}`,
383
- body: `This PR was migrated from a fork to allow secrets to run in workflows. Check the [original PR](https://github.com/ansys/pymapdl/pull/${prNumber}) for more details.
394
+ head: prBaseBranch, // This is the branch we just created which becomes now the head of the PR, and the base (target) branch is the main branch.
395
+ base: 'main',
396
+ title: `chore: [migrated PR ${prNumber}] ${originalPR.title}`,
397
+ body: `This PR is a mirror pull request created from [${originalPR.title}](https://github.com/ansys/pymapdl/pull/${originalPR.number}) to allow the code to access PyMAPDL CICD secrets.
398
+
399
+ Check the [original PR](https://github.com/ansys/pymapdl/pull/${originalPR.number}) made by @${originalPR.user.login} for more details.
384
400
385
401
Closes #${prNumber}`,
402
+
403
+ ## Original pull request
404
+
405
+ ### ${originalPR.title}
406
+ ${originalPR.body}
407
+
386
408
});
387
409
388
410
core.info(`New PR created: ${newPrData.data.number}`);
411
+
412
+ core.info(`Assinging PR to: ${userTriggering} and ${originalPR.user.login}`);
413
+ await octokit.request('POST /repos/{owner}/{repo}/issues/{issue_number}/assignees', {
414
+ owner: 'ansys',
415
+ repo: 'pymapdl',
416
+ issue_number: newPrData.data.number,
417
+ assignees: [
418
+ userTriggering, // The user who triggered the action
419
+ originalPR.user.login, // The original PR author
420
+ ],
421
+ headers: {
422
+ 'X-GitHub-Api-Version': '2022-11-28'
423
+ }
424
+ })
389
425
390
426
// React positively to the comment
391
427
github.rest.reactions.createForIssueComment({
@@ -399,10 +435,12 @@ jobs:
399
435
github.rest.issues.createComment({
400
436
owner: 'ansys',
401
437
repo: 'pymapdl',
402
- issue_number: '${{ env.PR_NUMBER }}' ,
438
+ issue_number: prNumber ,
403
439
body: `**:rocket: Migration completed!**
404
440
405
- The PR [#${newPrData.data.number}](${newPrData.data.html_url}) has been created successfully.`,
441
+ The PR [#${newPrData.data.number}](${newPrData.data.html_url}) has been created successfully.
442
+
443
+ Thank you @${userTriggering} for your contribution! Please review the PR and make any necessary changes.`,
406
444
});
407
445
408
446
- name : Create comment about failed migration
@@ -412,8 +450,8 @@ jobs:
412
450
github-token : ${{ secrets.PYANSYS_CI_BOT_TOKEN }}
413
451
script : |
414
452
// React positively to the comment
415
- commentId = '${{ env.COMMENT_ID }}' ;
416
- pr_number = '${{ env.PR_NUMBER }}' ;
453
+ commentId = process. env.COMMENT_ID;
454
+ pr_number = process. env.PR_NUMBER;
417
455
418
456
github.rest.reactions.createForIssueComment({
419
457
owner: 'ansys',
@@ -428,6 +466,6 @@ jobs:
428
466
issue_number: pr_number,
429
467
body: `**:x: Error :x:**
430
468
431
- An error occurred while migrating and syncing the PR. Please check the action logs for more details .`,
469
+ An error occurred while migrating or syncing the PR. Pinging @pymapdl-maintainers for assistance .`,
432
470
});
433
471
0 commit comments