-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
devops: Add ci warning for swizzled docusaurus components #9467
devops: Add ci warning for swizzled docusaurus components #9467
Conversation
Add new action and workflow that runs on new dependabot PR. The action checks changes in components of docusaurus-theme-openapi that are swizzled and warns maintainers to review those changes. For more info see badges#9287 Solves badges#9287
New dependencies detected. Learn more about Socket for GitHub ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this. This looks like it will be really useful.
I've had a read over the code and left you a first pass of comments. I've not actually run the code yet though. JS actions are very powerful, but one of the big issues is that it is quite hard to just check code like this out and run it locally to make sure it works.
How have you been testing this? Did you do it all in a test repo, or were you able to run bits of the code locally?
const pkgLockNewJson = await (await fetch(file.raw_url)).json() | ||
const pkgLockOldJson = await ( | ||
await fetch( | ||
`https://raw.githubusercontent.com/${github.context.repo.owner}/${github.context.repo.repo}/master/${file.filename}`, | ||
) | ||
).json() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to pull in node-fetch as a dependency and request these URLs. We've got an OctoKit instance in scope, so I think we should be able to use:
octokit.rest.repos.getContent({
owner,
repo,
path,
ref?,
});
to replace both these calls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am new to octokit, I will look into this and add this if applicable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
solved with db2e03c
notice that files are > 1MB therefor an getContent won't return content (tried even with raw)
I had to use the sha and make a new blob request.
if ( | ||
['dependabot[bot]', 'dependabot-preview[bot]'].includes(pr.user.login) | ||
) { | ||
const files = await getAllFilesForPullRequest( | ||
client, | ||
github.context.repo.owner, | ||
github.context.repo.repo, | ||
pr.number, | ||
) | ||
|
||
for (const file of files) { | ||
if (file.filename !== 'package-lock.json') { | ||
continue | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, it is harder to read large blocks of code that are deeply nested.
We can often work round nesting by taking some code like
if (condition) {
// do stuff
}
and re-writing it as
if (!condition) {
return
}
// do stuff
I think we could make this whole run
function easier to read by getting rid of a couple of layers of nesting here. For example:
if (!['dependabot[bot]', 'dependabot-preview[bot]'].includes(pr.user.login)) {
return
}
const file = files.filter(f => f.filename === 'package-lock.json')[0]
if (file === undefined) {
return
}
// do something with file
This would also make it clearer that we are not expecting to process more than one package-lock.json
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const packageName = 'docusaurus-theme-openapi' | ||
const packageParentName = 'docusaurus-preset-openapi' | ||
const overideComponents = ['Curl', 'Response'] | ||
const messageTemplate = `<table><thead><tr><th> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor points, but:
- If we have a look at your screenshot, we can see the table looks wierd because not all of the table rows have the same number of columns. Making these headers will fix that.
- We're using
<th>
for every cell in this table, but<th>
is only for headers. The "normal" cells should be<td>
s.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updating this, not sure what you mean at 1, but i used colspan="2"
to fix the visual issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"dependencies": { | ||
"@actions/core": "^1.10.0", | ||
"@actions/github": "^5.1.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are adding a package.json with dependencies here, we should register it with dependabot, like this:
shields/.github/dependabot.yml
Lines 33 to 41 in e9b3b50
# close-bot package dependencies | |
- package-ecosystem: npm | |
directory: '/.github/actions/close-bot' | |
schedule: | |
interval: weekly | |
day: friday | |
time: '12:00' | |
open-pull-requests-limit: 99 | |
rebase-strategy: disabled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Solved with c77af69
Co-authored-by: chris48s <chris48s@users.noreply.github.com>
Thank you for the code review and the useful insights. Regarding testing - I used a forked repo on github for testing, I think I might be able to run it locally if i look for some testing tools or try to simulate github with a crafted payload. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Latest changes look great - thanks. I've done a bit of testing on this in another repo. I found it a bit tricky to test this, but my experience is that when it comes to these GitHub actions, there is a large extent to which we can "set it and forget it". We don't tend to be constantly changing them. So I'm not too worried about this being a bit of a pain to test.
I've left a few final comments inline, but this is 99% done.
core.debug('Found changes and posted comment, done.') | ||
return | ||
} | ||
|
||
core.debug('No changes found, done.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make these log statements use core.info()
instead of core.debug()
so they always get logged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. This would be easier to understand.
Added with 78551ff
if (newVersionParent > newVersion) { | ||
newVersion = newVersionParent | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be useful here if we could write a log message here (again, core.info()
) with oldVersion
and newVersion
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added with 5311d03
@@ -0,0 +1,22 @@ | |||
name: Docusaurus swizzled component changes warning | |||
on: | |||
pull_request_target: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This workflow doesn't actually need to run on pull_request_target
. It can just run on pull_request
. I'm aware this is a copy & paste from close-bot, which probably could have also just used pull_request
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yea, my bad, didn't notice this when I started with close-bot as a ref for the file.
Fixed with 640567d
Change core.debug to core.info so it always shows and not only when in debug.
Log old and new versions for the Docusaurus swizzled component changes warning workflow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweeeet. Thanks for working on this one
Nicely done @jNullj! |
Add new action and workflow that runs on new dependabot PR.
The action checks changes in components of docusaurus-theme-openapi that are swizzled and warns maintainers to review those changes.
For more info see #9287
Solves #9287