2

pyGithub ( https://github.com/jacquev6/PyGithub ) API で作成した新しいブランチにプル リクエストを送信しようとしています。スクリプトを実行するたびに、さまざまな結果が得られます。ループの最後にプル リクエストを作成できる場合もあれば、マスター ブランチと作成した新しいブランチのコミットに違いがないというエラーが表示される場合もあります。これは、サブプロセスで呼び出されているため、「git push origin new_branch」コマンドが時間内に終了しないことが原因であると確信しています。続行する前に git 呼び出しが終了するのを待つにはどうすればよいですか? プロセスで .wait() を使用しようとしましたが、「サブプロセス」が終了するのを待つと思いますが、別のコマンドである git 呼び出しは待ちません。これを行う方法はありますか?または多分私は' 私はこれについて間違った方法で行っています。私のコード:

from github import Github
import getpass
import subprocess

username = input("Please enter your GitHub username: ")
password = getpass.getpass()
g = Github(username, password)

base_branch = input("Please enter your base branch, default --> [master]: ")
base_branch = base_branch or 'master'

new_branch = input("Please enter your new branch name: ")

authorName = input("Please enter the github organization name: ")
# author validation
try:
    author = g.get_organization(authorName)
except GithubException as ghe:
    print(ghe)

repos = input("Please enter a comma separated list of repo names: ").split(',')

# projects validation
if repos[0] == '':
    repos = input("No repos entered. \n Please enter a comma separated list of repos names: ").split(',')

for repo in repos:
    # retrieve info on the base_branch
    repoObj = author.get_repo(repo)
    baseBranch = repoObj.get_branch(base_branch)

    # create the new branch
    repoObj.create_git_ref('refs/heads/'+new_branch, baseBranch.commit.sha)

    # touch readme.md in the new branch and commit the change
    subprocess.call(['git', 'checkout', '-B', new_branch, 'origin/' + base_branch], cwd='./' + repo)
    subprocess.call("echo '' >> README.md", shell=True, cwd='./' + repo)
    subprocess.call(['git', 'commit', '-am "First Commit:"' + new_beanch + '"'], cwd='./' + repo)
    pushProcess = subprocess.call(['git', 'push', 'origin', new_branch], cwd='./' + repo)
    pushProcess.wait()

    newBranch = repoObj.get_branch(new_branch)
    # create pull request
    repoObj.create_pull(release_title, 'Main Release Ticket: ',baseBranch.commit.sha,newBranch.commit.sha)
4

0 に答える 0