Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Transfer the ownership of multiple bitbucket repos using Puppeteer browser automation
const puppeteer = require("puppeteer-core");
const currentOwnerUsername = "", currentOwnerPassword = "", transferToOwnerUsername = "",
loginUrl = "https://bitbucket.org/account/signin/", chromePath = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe";
// list of repos to change ownership for
const repos = [
"https://bitbucket.org/{username}/{repo-name}"
];
(async () => {
const browser = await puppeteer.launch({
executablePath: chromePath, headless: false, args: [
"--start-maximized"
]
});
const context = await browser.createIncognitoBrowserContext();
const page = await context.newPage();
await page.setViewport({ width: 1920, height: 938 });
await page.goto(loginUrl)
.then(_ => page.waitForSelector("#username"))
.then(u => u.type(currentOwnerUsername))
.then(_ => page.click("#login-submit"))
.then(_ => page.waitForSelector(".field-group.password-field.expanded #password"))
.then(p => p.type(currentOwnerPassword))
.then(_ => page.click("#login-submit"))
.then(_ => page.waitForSelector(".override-aui.text"))
.then(_ => page.waitForNavigation());
for (const repo of repos) {
await page.goto(repo)
.then(_ => page.waitForSelector("#xfer-repo-btn")).then(e => e.click())
.then(_ => page.waitForSelector("#xfer-repo-dialog[aria-hidden=false]")).then(_ => page.type("#id_user", transferToOwnerUsername))
.then(_ => page.click(".aui-button-warning.dialog-submit"))
.then(_ => page.waitForSelector("#transfer-accept-button")).then(b => b.click())
.then(_ => page.waitForSelector("#user-access"))
}
await browser.close();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.