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

GODRIVER-3008 Add mongodb-drivers-comment-bot support #361

Merged
merged 24 commits into from
Oct 16, 2023

Conversation

blink1073
Copy link
Member

Used with mongodb/mongo-go-driver#1424 to create an API report comment:

image

@blink1073
Copy link
Member Author

blink1073 commented Oct 13, 2023

@baileympearson I added you as a reviewer since this is a node app and it involves bootstrapping nvm.

Copy link

@qingyang-hu qingyang-hu left a comment

Choose a reason for hiding this comment

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

It looks good based on my limited knowledge of node.

mkdir -p $NVM_DIR
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm install lts/hydrogen
Copy link
Contributor

Choose a reason for hiding this comment

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

So - we don't actually use nvm in CI anymore. nvm installs globally by default, which modifies the evergreen host the task is running on. nvm on non-windows machines has a way to work around this, but I think windows does not (we switched off of using nvm sometime last year for this reason). So we maintain our own script to download the latest LTS build of a given Node major version: https://github.com/mongodb/node-mongodb-native/blob/main/.evergreen/install-dependencies.sh. We then use https://github.com/mongodb/node-mongodb-native/blob/main/.evergreen/init-node-and-npm-env.sh to add node and npm to the path when we need them.

If you're not running these on windows, you might be alright. But we could also consider moving these scripts into drivers-evergreen-tools (which would be a useful improvement for Node because we currently maintain like 10 different copies of these scripts across all the repos and branches we support. No exaggeration lol).

What do you think of that idea? I'll want to make sure this is alright with the Node team but I think that initially

  • we can just copy these scripts into drivers-evergreen-tools as-is and you can consume them in this PR
  • Node will continue to maintain them
  • the Node team can eventually adopt them and transition our CI to use them

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh nice, I like the idea of copying over those scripts as part of this PR, independent of what your team ends up doing. I had intended this script to be run on a Linux host, but using the "standard" approach sounds better overall.

Copy link
Member Author

Choose a reason for hiding this comment

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

I made a couple of tweaks: the default LTS is 18, and it uses local paths instead of PROJECT_DIRECTORY. I'm testing it now again.

.evergreen/github_app/create_or_modify_comment.mjs Outdated Show resolved Hide resolved
.evergreen/github_app/create_or_modify_comment.mjs Outdated Show resolved Hide resolved
.evergreen/github_app/create_or_modify_comment.mjs Outdated Show resolved Hide resolved
Comment on lines 71 to 85
resp.data.forEach(async (comment) => {
if (comment.body.includes(bodyMatch)) {
if (found) {
return
}
found = true;
await octokit.request("PATCH /repos/{owner}/{repo}/issues/comments/{comment_id}", {
owner,
repo,
body: bodyText,
comment_id: comment.id,
headers
});
}
})
Copy link
Contributor

Choose a reason for hiding this comment

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

In Node, you need to be careful of using async functions as callbacks where they're not expected, because if the async function throws an error, it won't be caught and the program crashes. Here I'd either use Array.find() again, or use a for-of loop

Suggested change
resp.data.forEach(async (comment) => {
if (comment.body.includes(bodyMatch)) {
if (found) {
return
}
found = true;
await octokit.request("PATCH /repos/{owner}/{repo}/issues/comments/{comment_id}", {
owner,
repo,
body: bodyText,
comment_id: comment.id,
headers
});
}
})
const comment = resp.data.find(comment => comment.body.includes(bodyMatch));
if (!comment) {
// create comment
}
// update comment

or

for (const comment of resp.data)
    if (comment.body.includes(bodyMatch)) {
        found = true;
        await octokit.request("PATCH /repos/{owner}/{repo}/issues/comments/{comment_id}", {
            owner,
            repo,
            body: bodyText,
            comment_id: comment.id,
            headers
        });
        break;
    }
}

Copy link
Member Author

Choose a reason for hiding this comment

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

👍🏼

@blink1073
Copy link
Member Author

All green again on both sides!

@blink1073 blink1073 merged commit 995635b into mongodb-labs:master Oct 16, 2023
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants