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

Autobot: Automate Merging Dependabot PRs #65

Open
nelsonic opened this issue Jul 18, 2022 · 16 comments
Open

Autobot: Automate Merging Dependabot PRs #65

nelsonic opened this issue Jul 18, 2022 · 16 comments

Comments

@nelsonic
Copy link
Owner

nelsonic commented Jul 18, 2022

document
  .querySelectorAll(".octicon-git-pull-request.color-fg-open")[0]
  .closest(".notification-list-item-link")
  .click();

setTimeout(() => {
  document
    .querySelectorAll(".octicon-file-diff")[0]
    .closest(".tabnav-tab")
    .click();

  setTimeout(() => {
    document.querySelectorAll(".js-reviews-toggle")[0].click();
    var text = "Thanks @dependabot 🤖 👌";
    document.getElementById("pull_request_review_body").value = text;
    document.querySelectorAll('[value="approve"]')[0].click();
    document.querySelectorAll("button.float-left")[1].click();
  }, 2000);
}, 2000);

Followed by:

document.querySelectorAll(".hx_create-pr-button")[0].click();
document.querySelectorAll(".js-merge-commit-button")[0].click();

setTimeout(() => {
  document.querySelectorAll('[title="Done"]')[0].click();
}, 2000);

# Context:

We have quite a few Elixir/Phoenix projects ... github.com/dwyl?q=language=elixir

so when a random dependency is patched and Dependabot creates Pull Requests to update it,
we get this kind of thing:
image

I don't want to merge them all without supervision because I want to be informed of the updates.
But I do want to a generic script I can use to automate.
Think of it as "supervised automation" 😜

@nelsonic
Copy link
Owner Author

Using my DOM script from #1 as the starting point.

This works manually in Chrome/FF dev tools:

function run() {
  document
    .querySelectorAll(".octicon-git-pull-request.color-fg-open")[0]
    .closest(".notification-list-item-link")
    .click();

  setTimeout(() => {
    document
      .querySelectorAll(".octicon-file-diff")[0]
      .closest(".tabnav-tab")
      .click();

    setTimeout(() => {
      document.querySelectorAll(".js-reviews-toggle")[0].click();
      var text = "Thanks @dependabot 🤖 👌";
      document.getElementById("pull_request_review_body").value = text;
      document.querySelectorAll('[value="approve"]')[0].click();
      document.querySelectorAll("button.float-left")[2].click();
      next();
    }, 5000);
  }, 5000);
}
run();

function next() {
  setTimeout(() => {
    document.querySelectorAll(".hx_create-pr-button")[0].click();
    document.querySelectorAll(".js-merge-commit-button")[0].click();

    setTimeout(() => {
      document.querySelectorAll('[title="Done"]')[0].click();
      run();
    }, 4000);
  }, 4000);
}

Due to the full-page-refresh when submitting a PR review which is both server and client rendered 🙄
It cannot be run "unsupervised" ... 🤦‍♂️
Considering building a chrome extension for this. 💭

@nelsonic
Copy link
Owner Author

OK. not going to waste any more time on this. It's definitely a distraction!!

But when I need the script it's better to run it in two stages:

document
  .querySelectorAll(".octicon-git-pull-request.color-fg-open")[0]
  .closest(".notification-list-item-link")
  .click();

setTimeout(() => {
  document
    .querySelectorAll(".octicon-file-diff")[0]
    .closest(".tabnav-tab")
    .click();

  setTimeout(() => {
    document.querySelectorAll(".js-reviews-toggle")[0].click();
    var text = "Thanks @dependabot 🤖 👌";
    document.getElementById("pull_request_review_body").value = text;
    document.querySelectorAll('[value="approve"]')[0].click();
    document.querySelectorAll("button.float-left")[2].click();
  }, 3000);
}, 3000);

Followed by:

document.querySelectorAll(".hx_create-pr-button")[0].click();
document.querySelectorAll(".js-merge-commit-button")[0].click();

setTimeout(() => {
  document.querySelectorAll('[title="Done"]')[0].click();
}, 4000);

because the DOM loading is incredibly unreliable!

@nelsonic
Copy link
Owner Author

Quick demo:

autobot-demo.mov

@nelsonic nelsonic pinned this issue Jul 18, 2022
@nelsonic
Copy link
Owner Author

Once you have run both script blocks once you can use the up arrow and enter keys to repeat. ♻️
This is considerably faster than clicking through, typing, clicking, waiting, locating buttons ... ⏳ 🙄

@nelsonic nelsonic changed the title Automate Merging Dependabot PRs Autobot: Automate Merging Dependabot PRs Jul 18, 2022
nelsonic added a commit that referenced this issue Jul 18, 2022
@nelsonic
Copy link
Owner Author

Reading: https://violentmonkey.github.io/get-it/

image

Given that Microsoft already know everything I'm doing on GitHub ...
Considering installing Edge browser: https://www.microsoft.com/en-us/edge
image

And using it as my GitHub Notifications browser ... 💭

@nelsonic
Copy link
Owner Author

Let's come back to this.

@nelsonic
Copy link
Owner Author

Top tip. if you don't quite the Chrome App your DevTools Console history maintains any scripts/code you have run so even though I had closed the tab I could still retrieve the script from history. just used it. so glad I wrote it. let's see how long the DOM attributes/classes last before GH inevitably does another re-design. 🙄

@nelsonic
Copy link
Owner Author

Installing Microsoft Edge on Mac requires 730 MB of storage ... 🙄
image

@nelsonic
Copy link
Owner Author

🙄
image

@nelsonic
Copy link
Owner Author

Literally just downloaded Edge from the Microsoft site and there's already an update ...
image

Not even 5 mins later. 🤦‍♂️
Why didn't they just update the binary and save me this noise?!

@nelsonic
Copy link
Owner Author

Yay! GitHub updated their markup, again ... 🎉 (🙄)
image

Gotta update the script. 🧑‍💻 ⌛

@nelsonic
Copy link
Owner Author

Easy enough, the number of buttons on the page was reduced from 3 to 2 so the index for the "Submit review" button is now 1 not 2:

document
  .querySelectorAll(".octicon-git-pull-request.color-fg-open")[0]
  .closest(".notification-list-item-link")
  .click();

setTimeout(() => {
  document
    .querySelectorAll(".octicon-file-diff")[0]
    .closest(".tabnav-tab")
    .click();

  setTimeout(() => {
    document.querySelectorAll(".js-reviews-toggle")[0].click();
    var text = "Thanks @dependabot 🤖 👌";
    document.getElementById("pull_request_review_body").value = text;
    document.querySelectorAll('[value="approve"]')[0].click();
    document.querySelectorAll("button.float-left")[1].click();
  }, 2000);
}, 2000);

I would still like to make the whole script run as one but now is not the time to be messing with that because of network latency ... ⏳

@nelsonic
Copy link
Owner Author

nelsonic commented Jun 7, 2023

var links = document
  .querySelectorAll(".octicon-git-pull-request.color-fg-open");
links[links.length - 1].closest(".notification-list-item-link").click();
setTimeout(() => {
  document
    .querySelectorAll(".octicon-file-diff")[0]
    .closest(".tabnav-tab")
    .click();

  setTimeout(() => {
    document.querySelectorAll(".js-reviews-toggle")[0].click();
    var text = "Thanks @dependabot 🤖 👌";
    document.getElementById("pull_request_review_body").value = text;
    document.querySelectorAll('[value="approve"]')[0].click();
    document.querySelectorAll("button.float-left")[1].click();
  }, 2000);
}, 2000);

@nelsonic
Copy link
Owner Author

nelsonic commented Jun 7, 2023

document.querySelectorAll(".hx_create-pr-button")[0].click();
document.querySelectorAll(".js-merge-commit-button")[0].click();

setTimeout(() => {
  document.querySelectorAll('[aria-label="Done"]')[0].click();
}, 2000);

@nelsonic
Copy link
Owner Author

nelsonic commented Jul 12, 2023

Attempt single script:

var links = document
  .querySelectorAll(".octicon-git-pull-request.color-fg-open");
links[links.length - 1].closest(".notification-list-item-link").click();
setTimeout(() => {
  document
    .querySelectorAll(".octicon-file-diff")[0]
    .closest(".tabnav-tab")
    .click();

  setTimeout(() => {
    document.querySelectorAll(".js-reviews-toggle")[0].click();
    var text = "Thanks @dependabot 🤖 👌";
    document.getElementById("pull_request_review_body").value = text;
    document.querySelectorAll('[value="approve"]')[0].click();
    document.querySelectorAll("button.float-left")[1].click();
    // merge:
    setTimeout(() => {
        document.querySelectorAll(".hx_create-pr-button")[0].click();
        document.querySelectorAll(".js-merge-commit-button")[0].click();
        
        setTimeout(() => {
          document.querySelectorAll('[aria-label="Done"]')[0].click();
        }, 1000);
    }, 2000);
  }, 2000);
}, 2000);

@nelsonic
Copy link
Owner Author

If someone has merged a bunch of @dependabot PRs e.g:

image

Then the above script breaks because the DOM has changed. 🤦‍♂️

document
  .querySelectorAll(".notification-list-item-link")[0]
  .click()

setTimeout(() => {
  document
    .querySelectorAll(".octicon-file-diff")[0]
    .closest(".tabnav-tab")
    .click();

  setTimeout(() => {
    document.querySelectorAll(".js-reviews-toggle")[0].click();
    var text = "Thanks @dependabot 🤖 👌";
    document.getElementById("pull_request_review_body").value = text;
    document.querySelectorAll("button.float-left")[1].click();
    setTimeout(() => {
      document.querySelectorAll('[aria-label="Done"]')[0].click();
    }, 3000);
  }, 2000);
}, 2000);

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

No branches or pull requests

1 participant