Hi, I have a project with 20 repos. I would like to get a list of file names for each repo (in the main branch -some are called 'master', some 'main'-).
How do I go about doing this?
I saw this answer in another question, but it didn't really work for me. This is specifically what I tried (to get all the files in one repo's master branch):
Where am I going wrong? Ideally I would like to get all files under all repos inside a given project in one call, but if that's not possible I can settle for making an API call per repo to get each of their list of files. I don't need the content, just the file names.
Alright, in the end I just devised a way to do it via JS from the browser (couldn't find any way to do this directly with the Bitbucket API):
//The way to run this script is through DevTools (Ctrl+Shift+i) > Sources > '>>' > Snippets > New snippet > copy paste the script there
//> run it (while in https://<your-bitbucket-domain>/projects/<your-project-name>
//STEP 1: extracts the urls of all repos under <your-project-name>
let array = document.getElementsByClassName("repository-name");
let links = Array.from(array).map(x=>x.outerHTML.match(/<a[^>]+href=\"(.*?)\"[^>]*>(.*)?<\/a>/));
// console.log(links); // (25) ["/projects/<your-proj>/repos/<repo-name>/browse"...]
let repoNames = links.map(x=>x.split("/").slice(-2,-1)).flat(); //["repoA", "repoB", "repoC", ...]
//STEP 2: fetches the html of a given url and extracts repo file names
let parser = new DOMParser();
.then(response => response.text())
htmlDoc = parser.parseFromString(data, 'text/html');
// $('') is an alias for document.querySelector
// $$('') is an alias for document.querySelectorAll
The end result looks like:
['repoA', 'readme.md', 'contributing.md'...]
['repoB', '.gitignore', ...]
Hope it helps
Beginning on April 4th, we will be implementing push limits. This means that your push cannot be completed if it is over 3.5 GB. If you do attempt to complete a push that is over 3.5 GB, it will fail...
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events