Skip to content

Commit b8a2bed

Browse files
germa89pyansys-ci-botclatapie
authored
ci: update branch in migrator (#3973)
* feat: getting rid of useless merge and doing the pull after checkout to avoid conflicts. We merge with main later, and apply the logic. * refactor: using backticks to preserve newlines. * chore: adding changelog file 3973.maintenance.md [dependabot-skip] * feat: enhance PR migration process with original PR details and user assignment * fix: update PR title format and correct maintainer mention in migration workflow --------- Co-authored-by: pyansys-ci-bot <[email protected]> Co-authored-by: Camille Latapie <[email protected]>
1 parent 628dde1 commit b8a2bed

File tree

2 files changed

+65
-26
lines changed

2 files changed

+65
-26
lines changed

.github/workflows/migrator.yml

Lines changed: 64 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,19 @@ jobs:
7979
let prNumber, userTriggering, commentBody;
8080
8181
if (eventName === "workflow_dispatch") {
82-
core.info('Running in workflow_dispatch mode');
82+
core.info('Running in "workflow_dispatch" mode');
8383
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 }}`;
8888
} else {
89-
core.info('Running in issue_comment mode');
89+
core.info('Running in "issue_comment" mode');
9090
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 }}`;
9595
}
9696
core.debug(`PR Number: ${prNumber}`);
9797
core.debug(`User triggering: ${userTriggering}`);
@@ -275,6 +275,7 @@ jobs:
275275
core.exportVariable('PR_HEAD_REPO', data.head.repo.full_name);
276276
core.exportVariable('PR_BASE_BRANCH', `migration/pr-${{ env.PR_NUMBER }}`);
277277
core.exportVariable('PR_BASE_REPO', data.base.repo.full_name);
278+
278279
} else {
279280
throw new Error('Failed to retrieve pull request details');
280281
}
@@ -295,20 +296,25 @@ jobs:
295296
git config --global user.email "${{ secrets.PYANSYS_CI_BOT_EMAIL}}"
296297
git config pull.rebase true
297298
298-
echo "Adding ${{ env.PR_HEAD_REPO }} as remote"
299+
echo "\033[1;92m[INFO]Adding ${{ env.PR_HEAD_REPO }} as remote \033[0m"
299300
git remote add head_repo https://x-access-token:${{ secrets.PYANSYS_CI_BOT_TOKEN }}@github.com/${{ env.PR_HEAD_REPO }}.git
300301
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"
302303
git fetch head_repo ${{ env.PR_HEAD_BRANCH }}
303-
git pull head_repo ${{ env.PR_HEAD_BRANCH }}
304304
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"
306306
git checkout -b ${{ env.PR_BASE_BRANCH }} head_repo/${{ env.PR_HEAD_BRANCH }}
307307
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
310315
CONFLICTS=$(git ls-files -u | wc -l)
311-
echo "CONFLICTS=$CONFLICTS"
316+
echo "Merge conflicts:"
317+
echo "${CONFLICTS}"
312318
313319
if [[ "$CONFLICTS" -gt 0 && -n "${{ env.MODE }}" ]]; then
314320
echo "::warning:: Conflicts trying to solve using mode '${{ env.MODE }}'."
@@ -355,6 +361,7 @@ jobs:
355361
const prHeadRepo = process.env.PR_HEAD_REPO;
356362
const prBaseBranch = process.env.PR_BASE_BRANCH;
357363
const prBaseRepo = process.env.PR_BASE_REPO;
364+
const userTriggering = process.env.USER_TRIGGERING;
358365
359366
core.debug(`Listing existing PRs for branch ${prBaseBranch}...`);
360367
const existingPrs = await github.rest.pulls.list({
@@ -372,20 +379,49 @@ jobs:
372379
return;
373380
}
374381
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+
375389
// https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#create-a-pull-request
376390
newPrData = await github.rest.pulls.create({
377391
owner: 'ansys',
378392
repo: 'pymapdl',
379393
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.
384400
385401
Closes #${prNumber}`,
402+
403+
## Original pull request
404+
405+
### ${originalPR.title}
406+
${originalPR.body}
407+
386408
});
387409
388410
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+
})
389425
390426
// React positively to the comment
391427
github.rest.reactions.createForIssueComment({
@@ -399,10 +435,12 @@ jobs:
399435
github.rest.issues.createComment({
400436
owner: 'ansys',
401437
repo: 'pymapdl',
402-
issue_number: '${{ env.PR_NUMBER }}',
438+
issue_number: prNumber,
403439
body: `**:rocket: Migration completed!**
404440
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.`,
406444
});
407445
408446
- name: Create comment about failed migration
@@ -412,8 +450,8 @@ jobs:
412450
github-token: ${{ secrets.PYANSYS_CI_BOT_TOKEN }}
413451
script: |
414452
// 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;
417455
418456
github.rest.reactions.createForIssueComment({
419457
owner: 'ansys',
@@ -428,6 +466,6 @@ jobs:
428466
issue_number: pr_number,
429467
body: `**:x: Error :x:**
430468
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.`,
432470
});
433471
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ci: update branch in migrator

0 commit comments

Comments
 (0)