How to get a full list of repositories that a user is allowed to access?

前端 未结 4 1620
庸人自扰
庸人自扰 2021-01-04 01:29

I have found bitbucket api like:

https://bitbucket.org/api/2.0/repositories/{teamname}

But this link return 301 status (moved permanently t

4条回答
  •  灰色年华
    2021-01-04 01:57

    Expanding on blizzard's answer, here's a little node.js script I just wrote:

    import axios from 'axios';
    import fs from 'fs';
    
    
    async function main() {
        const bitbucket = axios.create({
            baseURL: 'https://api.bitbucket.org/2.0',
            auth: {
                username: process.env.BITBUCKET_USERNAME!,
                password: process.env.BITBUCKET_PASSWORD!,
            }
        });
    
        const repos = [];
        let next = 'repositories?role=member';
    
        for(;;) {
            console.log(`Fetching ${next}`)
            const res = await bitbucket.get(next);
            if(res.status < 200 || res.status >= 300) {
                console.error(res);
                return 1;
            }
            repos.push(...res.data.values);
            if(!res.data.next) break;
            next = res.data.next;
        }
        console.log(`Done; writing file`);
        await fs.promises.writeFile(`${__dirname}/../data/repos.json`,JSON.stringify(repos,null,2),{encoding:'utf8'});
    }
    
    
    main().catch(err => {
        console.error(err);
    });
    

提交回复
热议问题