Skip to content
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

lib/test: add initial prototype for wiby --test #3

Merged
merged 1 commit into from
Jun 29, 2020

Conversation

andrewhughes101
Copy link
Contributor

Intial protoype of tool, as demoed in the package maintenance meeting yesterday.

This PR contains the functionality to run wiby --test dependent_url which will take the HEAD commit from the repository the tool is being run from, and then update the package json of the dependent module provided to the tool as dependent_url.

lib/test.js Outdated Show resolved Hide resolved
Copy link
Member

@dominykas dominykas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Despite the comments, I think this is good to merge - we can always create separate issues for the things I noted in the interest of moving forward and having some code in the master that others can work on.

if (process.argv[2] === 'test') {
test()
const args = require('yargs')
.option('test', {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we consider test / result to be commands instead? e.g.

wiby test --dependent=[git url or github repo ref or package name from npm] --wait-for-results
wiby result --dependent=[git url or github repo ref or package name from npm]

This does have the downside that you can't --test --result like you do now, but maybe --wait-for-result or smth, which keeps polling for results, is good enough.

The upside is that this allows structuring the project with Yargs.commandDir(). I find that commands are also a nice way to expose and mirror the behavior between a package being a lib and a cli, i.e. require('wiby').test({ dependent: '@pkgjs/nv' }) can be equivalent to npx wiby test --dependent=@pkgjs/nv.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Covered by #7

const blobSha = await github.createBlob(owner, repo, encodedFile)
const newTreeSha = await github.createTree(owner, repo, treeSha, blobSha)
const commitSha = await github.createCommit(owner, repo, message, newTreeSha, headSha)
await github.createBranch(owner, repo, commitSha, branch)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't looked in detail, but I think it might be possible to do all of the above in a single API request: https://octokit.github.io/rest.js/v18#repos-create-or-update-file-contents.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Covered by #9

const file = JSON.stringify(packageJSON, null, 2) + '\n' // assumes package.json is using two spaces
const encodedFile = Buffer.from(file).toString('base64')
const message = `wiby: update ${dep}`
const branch = `wiby-${dep}`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does dep need sanitization here? Is @ an allowed character in a git branch (in case dep is a scoped package).

Should the branch and message also include some ref back to the hash / branch / PR of the dep being tested?


const fetchRegistryInfo = module.exports.fetchRegistryInfo =
async function fetchRegistryInfo (dep) {
const resp = await fetch(`https://registry.npmjs.org/${dep}`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use pacote for this, so that it can support custom registries. Happy to address this as part of #6.

const urlRegex = /github.com\/([^/])+\/[^/]+/g
const resp = await fetchRegistryInfo(dep)
let org, repo
if (resp.repository && resp.repository.url) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resp.repository can also be a string (the URL). And in this case git-url-parse is definitely handy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Covered by #10


const getOrgRepo = module.exports.getOrgRepo =
function getOrgRepo (url) {
const repoOrgArr = (url.split('github.com'))[1].split('/')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find https://www.npmjs.com/package/git-url-parse handy for things like this, esp. if we're going to support Github Enterprise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Covered by #10

Copy link
Member

@BethGriggs BethGriggs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @dominykas, let's land this and then iterate.

I also like the quite like the idea of the entry point being wiby test rather than wiby --test - I'll open an issue to follow up on that.

@andrewhughes101
Copy link
Contributor Author

Thanks for the reviews @dominykas @BethGriggs, Im going to land this, any outstanding items in the reviews I'll turn into new issues so anyone can work in parallel on them.

@andrewhughes101 andrewhughes101 merged commit 72daa5d into pkgjs:master Jun 29, 2020
@dominykas
Copy link
Member

🎉 This PR is included in version 0.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants