用于在bitbucket中自动创建项目和存储库的脚本

问题描述 投票:1回答:1

我正在将整套项目从TFS移动到Git.My项目结构如下:

Project 1:
---Repository1
---Repository2
---
---
---Repository10

Project 2:
---Repository1
---Repository2
---
---
---Repository20

因此,每个项目下有多个项目并包含多个存储库。当我将我的代码从本地存储库移动到Bitbucket时,我最终会分别手动创建每个项目和文件夹。相反,是否有任何脚本会在Bitbucket中为我自动创建Project和存储库的这个结构?如果是,有人可以分享一个例子吗? TIA!

编辑:我找到了一个可以实际执行此操作的脚本:https://bobswift.atlassian.net/wiki/spaces/SCLI/pages/87720019/How+to+create+projects+based+on+a+template

所以我的问题是,为了实现链接中提到的内容,我是否需要安装Bitbucket CLI或者我可以使用命令行界面完成它吗?

git bitbucket bitbucket-server bitbucket-api
1个回答
1
投票

这是我用来将存储库导入bitbucket的一些Perl:

#!/usr/bin/perl

use strict;
use warnings;
use Data::Dumper;
use File::Basename;
my $numArgs = $#ARGV + 1;

if($numArgs < 2) {
 die "Usage: $0 [Bit Bucket Project e.g. FW, BDPE] [repo name] [-d dry run (optional)]";
}

my $bitbucketProject = lc $ARGV[0];
my $repoName = $ARGV[1];
my $dryRun = $ARGV[2];
my %moduleHash;
my $bitBucketServer = "localhost";
my $user = "admin";
my $password = "bitbucket";


print "Bit Bucket Project: $bitbucketProject\n";
print "Repository name: $repoName\n";

sub importRepo {

     my $command = sprintf("curl -u %s:%s -X POST -H \"Content-Type: application/json\" -d '{
     \"name\": \"%s\",
     \"scmId\": \"git\",
     \"forkable\": true
     \}' http://%s:7990/rest/api/1.0/projects/%s/repos", $user, $password, $repoName, $bitBucketServer, $bitbucketProject); 

    if ($dryRun) {
      print "$command\n";
    } else {
    print "Doing import\n";
        system $command;
    }
    my $bitbucketUrl = sprintf("ssh://git\@%s:7999/%s/%s.git", $bitBucketServer, lc $bitbucketProject, $repoName);   
    my $gitCommand = sprintf("cd %s; pwd;  git repack -a -d -f; git push %s --mirror", $repoName, $bitbucketUrl);
    if ($dryRun) {
      print "$gitCommand\n";
    } else {   
       print "Running git\n";
       system $gitCommand;
    }

}

importRepo();

然后你可以用shell脚本环绕它:

#!/bin/bash

BITBUCKETPROJECT=$1

if [ $# -ne 2 ]; then
echo "Usage: $0 [Bit Bucket Project] [Path to repos]"
exit 1;
fi

echo "Bit bucket project: $BITBUCKETPROJECT"

    for f in *; do
        if [[ -d $f ]]; then
          echo $f
          ./importRepository.pl $BITBUCKETPROJECT $f 
        fi
    done

假设您的所有repos都已克隆到当前目录中。

https://developer.atlassian.com/static/rest/bitbucket-server/latest/bitbucket-rest.html

上面的例子没有在Bitbucket上创建项目,但它是一个起点。

© www.soinside.com 2019 - 2024. All rights reserved.