mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	fix: only comment if comment has not been added already
This commit is contained in:
		
							parent
							
								
									7a11ddc9c6
								
							
						
					
					
						commit
						b6c5d042d5
					
				
							
								
								
									
										53
									
								
								.github/workflows/core-feature-alert.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										53
									
								
								.github/workflows/core-feature-alert.yml
									
									
									
									
										vendored
									
									
								
							@ -18,25 +18,48 @@ jobs:
 | 
				
			|||||||
        id: pr-creator
 | 
					        id: pr-creator
 | 
				
			||||||
        run: echo "PR_CREATOR=${{ github.event.pull_request.user.login }}" >> $GITHUB_ENV
 | 
					        run: echo "PR_CREATOR=${{ github.event.pull_request.user.login }}" >> $GITHUB_ENV
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      - name: Post a notification about core feature changes
 | 
					      - name: Post a notification about core feature changes if not already commented
 | 
				
			||||||
        uses: actions/github-script@v6
 | 
					        uses: actions/github-script@v6
 | 
				
			||||||
        with:
 | 
					        with:
 | 
				
			||||||
          script: |
 | 
					          script: |
 | 
				
			||||||
            const prCreator = process.env.PR_CREATOR;
 | 
					            const prCreator = process.env.PR_CREATOR;
 | 
				
			||||||
            github.rest.issues.createComment({
 | 
					            const commentBody = `@${prCreator}, core features have been modified in this pull request. Please review!`;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            const { data: comments } = await github.rest.issues.listComments({
 | 
				
			||||||
              owner: context.repo.owner,
 | 
					              owner: context.repo.owner,
 | 
				
			||||||
              repo: context.repo.repo,
 | 
					              repo: context.repo.repo,
 | 
				
			||||||
              issue_number: context.payload.pull_request.number,
 | 
					              issue_number: context.payload.pull_request.number,
 | 
				
			||||||
              body: `@${prCreator}, core features have been modified in this pull request. Please review!`
 | 
					            });
 | 
				
			||||||
            })
 | 
					
 | 
				
			||||||
      # - name: Add reviewers to the PR
 | 
					            const alreadyCommented = comments.some(comment => comment.body === commentBody);
 | 
				
			||||||
      #   uses: actions/github-script@v6
 | 
					
 | 
				
			||||||
      #   with:
 | 
					            if (!alreadyCommented) {
 | 
				
			||||||
      #     script: |
 | 
					              await github.rest.issues.createComment({
 | 
				
			||||||
      #       const reviewers = ['FredrikOseberg'];
 | 
					                owner: context.repo.owner,
 | 
				
			||||||
      #       github.rest.pulls.requestReviewers({
 | 
					                repo: context.repo.repo,
 | 
				
			||||||
      #         owner: context.repo.owner,
 | 
					                issue_number: context.payload.pull_request.number,
 | 
				
			||||||
      #         repo: context.repo.repo,
 | 
					                body: commentBody,
 | 
				
			||||||
      #         pull_number: context.payload.pull_request.number,
 | 
					              });
 | 
				
			||||||
      #         reviewers: reviewers,
 | 
					              console.log('Posted a new comment.');
 | 
				
			||||||
      #       });
 | 
					            } else {
 | 
				
			||||||
 | 
					              console.log('Comment already exists, skipping.');
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					      - name: Add reviewers to the PR if they are not the creator
 | 
				
			||||||
 | 
					        uses: actions/github-script@v6
 | 
				
			||||||
 | 
					        with:
 | 
				
			||||||
 | 
					          script: |
 | 
				
			||||||
 | 
					            const prCreator = process.env.PR_CREATOR;
 | 
				
			||||||
 | 
					            const allReviewers = ['FredrikOseberg', 'gastonfournier'];
 | 
				
			||||||
 | 
					            const reviewersToAdd = allReviewers.filter(reviewer => reviewer !== prCreator);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (reviewersToAdd.length > 0) {
 | 
				
			||||||
 | 
					              github.rest.pulls.requestReviewers({
 | 
				
			||||||
 | 
					                owner: context.repo.owner,
 | 
				
			||||||
 | 
					                repo: context.repo.repo,
 | 
				
			||||||
 | 
					                pull_number: context.payload.pull_request.number,
 | 
				
			||||||
 | 
					                reviewers: reviewersToAdd,
 | 
				
			||||||
 | 
					              });
 | 
				
			||||||
 | 
					              console.log(`Added reviewers: ${reviewersToAdd.join(', ')}`);
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					              console.log(`No reviewers to add as all match the PR creator.`);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user