-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
60 changed files
with
731 additions
and
478 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,74 @@ | ||
module.exports = { | ||
getChangedPages: ({ github, context, buildDir }) => { | ||
getChangedPages: async ({ github, context, buildDir }) => { | ||
const fs = require('fs'); | ||
const cheerio = require('cheerio'); | ||
|
||
const urlList = []; | ||
|
||
const { | ||
issue: { number: issue_number }, | ||
repo: { owner, repo } | ||
} = context; | ||
|
||
// Use the Github API to query for the list of files from the PR | ||
return github | ||
.paginate( | ||
'GET /repos/{owner}/{repo}/pulls/{pull_number}/files', | ||
{ owner, repo, pull_number: issue_number }, | ||
(response) => response.data.filter((file) => (file.status === 'modified' || file.status === 'added')) | ||
) | ||
.then((files) => { | ||
const possiblePages = []; | ||
const platforms = [ | ||
'android', | ||
'angular', | ||
'flutter', | ||
'javascript', | ||
'nextjs', | ||
'react', | ||
'react-native', | ||
'swift', | ||
'vue', | ||
] | ||
files.forEach(({filename}) => { | ||
const isPage = filename.startsWith('src/pages') && (filename.endsWith('index.mdx') || filename.endsWith('index.tsx')); | ||
if(isPage) { | ||
|
||
const path = filename.replace('src/pages', '').replace('/index.mdx', '').replace('/index.tsx', ''); | ||
if(path.includes('[platform]')) { | ||
platforms.forEach((platform) => { | ||
possiblePages.push(path.replace('[platform]', platform)); | ||
}) | ||
} else { | ||
possiblePages.push(path); | ||
} | ||
} | ||
}); | ||
|
||
const siteMap = fs.readFileSync(`${buildDir}/sitemap.xml`); | ||
|
||
const siteMapParse = cheerio.load(siteMap, { | ||
xml: true | ||
}); | ||
|
||
siteMapParse('url').each(function () { | ||
urlList.push(siteMapParse(this).find('loc').text()); | ||
}); | ||
|
||
const pages = possiblePages.filter((page) => urlList.includes(`https://docs.amplify.aws${page}/`)); | ||
|
||
return pages; | ||
}); | ||
}, | ||
} | ||
const possiblePages = []; | ||
const platforms = [ | ||
'android', | ||
'angular', | ||
'flutter', | ||
'javascript', | ||
'nextjs', | ||
'react', | ||
'react-native', | ||
'swift', | ||
'vue' | ||
]; | ||
|
||
const changedFiles = await github.paginate( | ||
'GET /repos/{owner}/{repo}/pulls/{pull_number}/files', | ||
{ owner, repo, pull_number: issue_number }, | ||
(response) => | ||
response.data.filter( | ||
(file) => file.status === 'modified' || file.status === 'added' | ||
) | ||
); | ||
|
||
// Get only the changed files that are pages and build out the | ||
// possiblePages array | ||
changedFiles.forEach(({ filename }) => { | ||
const isPage = | ||
filename.startsWith('src/pages') && | ||
(filename.endsWith('index.mdx') || filename.endsWith('index.tsx')); | ||
if (isPage) { | ||
const path = filename | ||
.replace('src/pages', '') | ||
.replace('/index.mdx', '') | ||
.replace('/index.tsx', ''); | ||
if (path.includes('[platform]')) { | ||
platforms.forEach((platform) => { | ||
possiblePages.push(path.replace('[platform]', platform)); | ||
}); | ||
} else { | ||
possiblePages.push(path); | ||
} | ||
} | ||
}); | ||
|
||
// Get the sitemap and parse for an array of site URLs | ||
const siteMap = fs.readFileSync(`${buildDir}/sitemap.xml`); | ||
|
||
const siteMapParse = cheerio.load(siteMap, { | ||
xml: true | ||
}); | ||
|
||
siteMapParse('url').each(function () { | ||
urlList.push(siteMapParse(this).find('loc').text()); | ||
}); | ||
|
||
// Filter the possiblePages for only those that are part of the sitemap | ||
const pages = possiblePages.filter((page) => | ||
urlList.includes(`https://docs.amplify.aws${page}/`) | ||
); | ||
|
||
return pages; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.