Skip to content

Commit

Permalink
Merge pull request #2764 from mashehu/fix-add-netlify-link-3
Browse files Browse the repository at this point in the history
try different variable name
  • Loading branch information
mashehu authored Oct 4, 2024
2 parents 3206f32 + 523d3b1 commit 9342582
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions .github/workflows/add-netlify-link.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,46 +22,60 @@ jobs:
script: |
let changedFiles = `${{ steps.changed-files.outputs.all_changed_files }}`.split(' ').slice(0, 50);
console.log('Changed files:', changedFiles)
# remove the sites/** prefix until src
changedFiles = changedFiles.map(file => file.replace(/^sites\/[^/]+\//, ''));
// remove the sites/** prefix until src
const processedFiles = changedFiles.map(file => file.replace(/^sites\/[^/]+\//, ''));
console.log('Processed files:', processedFiles);
// handle normal pages
let netlifyLinks = changedFiles
let netlifyLinks = processedFiles
.filter(file => file.startsWith('src/pages/'))
.filter(file => !file.endsWith('].astro')) // skip dynamic routes
.map(file => `@netlify ${file?.replace('src/pages/', '/')}`)[0]
?.replace(/\.md$/, '').replace(/\.mdx$/, '').replace(/\.astro$/, '').replace(/\/index$/, '');
?.replace(/\.md$/, '')
.replace(/\.mdx$/, '')
.replace(/\.astro$/, '')
.replace(/\/index$/, '');
// handle pages in content collections
if (!netlifyLinks) {
netlifyLinks = changedFiles
netlifyLinks = processedFiles
.filter(file => file.startsWith('src/content/'))
.map(file => `@netlify ${file?.replace('src/content/', '/')}`)[0]
?.replace(/\.md$/, '').replace(/\.mdx$/, '').replace(/\/index$/, '');
?.replace(/\.md$/, '')
.replace(/\.mdx$/, '')
.replace(/\/index$/, '');
}
console.log('Netlify links:', netlifyLinks)
console.log('Netlify links:', netlifyLinks);
if (netlifyLinks) {
console.log('Adding Netlify link to PR body' ,context.payload.pull_request.number);
console.log('Adding Netlify link to PR body', context.payload.pull_request.number);
const { data: pullRequest } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
});
console.log('Current PR:', pullRequest);
console.log('Current PR body:', pullRequest.body);
const currentBody = pullRequest.body || '';
if (currentBody.includes('@netlify')) {
return; // Skip if the PR body already contains a Netlify link
}
const newBody = `${currentBody}\n\n${netlifyLinks}`;
console.log('New PR body:', newBody);
// Update the pull request body
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pullRequest.number,
body: newBody,
});
console.log('Netlify link added to PR body');
}

0 comments on commit 9342582

Please sign in to comment.