2020 name : Find Exercise Issue
2121 uses : skills/exercise-toolkit/.github/workflows/find-exercise-issue.yml@v0.7.1
2222
23- # À l'ouverture ou mise à jour de la PR, on affiche l'Étape 4 (merge)
23+ # 1) À l'ouverture/ mise à jour de la PR, afficher l'Étape 4 (merge)
2424 step4_merge_guidance :
2525 name : Step 4, merge guidance
2626 needs : [find_exercise]
7575 vars : |
7676 status_line: ${{ steps.status.outputs.line }}
7777
78- # À la fermeture mergée, on finalise
78+ # 2) Au merge, lancer le workflow de fin
7979 finish_exercise :
8080 name : Finish Exercise
8181 needs : [find_exercise]
8686 exercise-title : " GitHub Basics"
8787 update-readme-with-congratulations : false
8888
89+ # 3) Remplacer le commentaire "Congratulations..." par une version FR
90+ fr_congrats_comment :
91+ name : Replace official congrats with FR
92+ needs : [find_exercise, finish_exercise]
93+ if : ${{ github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true }}
94+ runs-on : ubuntu-latest
95+ env :
96+ ISSUE_NUMBER : ${{ needs.find_exercise.outputs.issue-number }}
97+ steps :
98+ - name : Replace EN comment with FR body
99+ uses : actions/github-script@v7
100+ with :
101+ script : |
102+ const {owner, repo} = context.repo;
103+ const issue_number = Number('${{ env.ISSUE_NUMBER }}');
104+
105+ // Corps FR de remplacement
106+ const frBody = [
107+ `🎉 Félicitations @${context.actor} tu as terminé l’exercice **GitHub Basics**.`,
108+ `Le dépôt a été mis à jour pour marquer la réussite, et le README affiche un message de félicitations en français.`,
109+ `➡️ Retourne à la page d’accueil du dépôt pour voir le résultat.`
110+ ].join('\n\n');
111+
112+ // Cherche le dernier commentaire du bot contenant "Congratulations"
113+ const { data: comments } = await github.rest.issues.listComments({
114+ owner, repo, issue_number, per_page: 100, sort: 'created', direction: 'desc'
115+ });
116+
117+ const target = comments.find(c =>
118+ c.user?.login === 'github-actions[bot]' &&
119+ /Congratulations|You finished the exercise/i.test(c.body || '')
120+ );
121+
122+ if (target) {
123+ await github.rest.issues.updateComment({ owner, repo, comment_id: target.id, body: frBody });
124+ } else {
125+ // Par sécurité, si on ne trouve pas le commentaire EN on poste le FR
126+ await github.rest.issues.createComment({ owner, repo, issue_number, body: frBody });
127+ }
128+
129+ # 4) Mettre à jour le README avec le bloc de félicitations
89130 finalize_fr :
90131 name : Finalize FR
91- needs : [find_exercise, finish_exercise]
132+ needs : [find_exercise, finish_exercise, fr_congrats_comment ]
92133 if : ${{ github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true }}
93134 runs-on : ubuntu-latest
94135 env :
@@ -114,6 +155,7 @@ jobs:
114155 const shareX = `https://twitter.com/intent/tweet?text=${enc}`;
115156 const shareBsky = `https://bsky.app/intent/compose?text=${enc}`;
116157 const shareLinkedIn = `https://www.linkedin.com/feed/?shareActive=true&text=${enc}`;
158+
117159 const lines = [
118160 '<div align="center">',
119161 '',
@@ -175,9 +217,10 @@ jobs:
175217 git pull --rebase origin main || true
176218 git push origin HEAD:main
177219
220+ # 5) Revue finale en FR, publiée après remplacement du message et màj du README
178221 post_review_content :
179222 name : Post review content, after merge
180- needs : [find_exercise, finalize_fr]
223+ needs : [find_exercise, fr_congrats_comment, finalize_fr]
181224 if : ${{ github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true }}
182225 runs-on : ubuntu-latest
183226 env :
@@ -201,6 +244,7 @@ jobs:
201244 issue-number : ${{ env.ISSUE_NUMBER }}
202245 file : ${{ env.REVIEW_FILE }}
203246
247+ # 6) Désactivation une fois tout terminé
204248 disable_step3 :
205249 name : Disable Step 3
206250 needs : [post_review_content]
@@ -211,4 +255,4 @@ jobs:
211255 run : gh workflow disable ".github/workflows/3-last-step.yml"
212256 env :
213257 GH_TOKEN : ${{ github.token }}
214- continue-on-error : true
258+ continue-on-error : true
0 commit comments