Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python git服务器端钩子_Python_Git_Ssh_Jira_Githooks - Fatal编程技术网

Python git服务器端钩子

Python git服务器端钩子,python,git,ssh,jira,githooks,Python,Git,Ssh,Jira,Githooks,我在服务器上运行follow python脚本查找推送的提交信息时遇到了一个问题。确保它遵循特定的语法,我无法从用户那里获得输入,这就是用户名和密码被硬编码的原因。我现在也无法获取在此特定推送之前发生的提交消息列表 #!/usr/bin/python import SOAPpy import getpass import datetime import sys import re import logging import os def login(x,y): try:

我在服务器上运行follow python脚本查找推送的提交信息时遇到了一个问题。确保它遵循特定的语法,我无法从用户那里获得输入,这就是用户名和密码被硬编码的原因。我现在也无法获取在此特定推送之前发生的提交消息列表

#!/usr/bin/python

import SOAPpy 
import getpass 
import datetime
import sys
import re
import logging
import os


def login(x,y):
    try:
        auth = soap.login(x, y)
        return auth
    except:
          sys.exit( "Invalid username or password")

def getIssue(auth,issue):
    try:
        issue = soap.getIssue(auth, issue)
    except:
        sys.exit("No issue of that type found : Make sure all PRs are vaild jira PRs")

def git_get_commit_msg(commit_id):
    return get_shell_cmd_output("git rev-list --pretty --max-count=1 " + commit_id)

def git_get_last_commit_id():
    return get_shell_cmd_output("git log --pretty=format:%H -1")

def getCommitText():
    commit_msg_filename = sys.argv[1]
    try:
        commit_msg_text = open(commit_msg_filename).read()
        return commit_msg_text
    except:
        sys.exit("Could not read commit message")

def git_get_array_of_commit_ids(start_id, end_id):
    output = get_shell_cmd_output("git rev-list " + start_id + ".." + end_id)
    if output == "":
        return None
    commit_id_array = string.split(output, '\n')
    return commit_id_array

def get_shell_cmd_output(cmd):
    try:
        proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
        return proc.stdout.read().rstrip('\n')
    except KeyboardInterrupt:
        logging.info("... interrupted")

    except Exception, e:
        logging.error("Failed trying to execute '%s'", cmd)

def findpattern(commit_msg):
    pattern = re.compile("\w\w*-\d\d*")
    group = pattern.findall(commit_msg)
    print group
    found = len(group)
    found =0
    issues = 0
    for match in group:
            auth = soap.login(jirauser,passwd)
            getIssue(auth,match)
            issues = issues + 1
            found+=1
    if found ==0:
        sys.exit("No issue patterns found.")

    print "Retrieved issues: " + str(issues)  

def update():
    print sys.argv[2]
    print sys.argv[3]
    old_commit_id = sys.argv[2]
    new_commit_id = sys.argv[3]
    commit_id_array = git_get_array_of_commit_ids(old_commit_id, new_commit_id)
    for commit_id in commit_id_array:
        commit_text = git_get_commit_msg(commit_id)
        findpattern(commit_text)

soap = SOAPpy.WSDL.Proxy('some url')
# this line if for repointing the input from dev/null
#sys.stdin = open('/dev/tty', 'r') # this fails horribly.
#ask user for input
#jirauser = raw_inp
#("Username for jira: ")
jirauser = "username"
passwd = "987654321"
#passwd = getpass.getpass("Password for %s: " % jirauser)
login(jirauser,passwd)
#commit_msg = getCommitText()
#findpattern(commit_msg)
update()
这段代码的预期目标是检查本地进行的提交,并通过它们解析预期的模式,以及检查in-jira中是否存在PR。它是一个服务器端钩子,在推送到存储库时被激活


任何关于编写python钩子的提示都将不胜感激。请,谢谢。

我建议您看看gitorious()。 他们使用ssh来处理身份验证和权限管理(获取ssh提供的用户名)。
他们在git存储库上也有一些钩子。我想这可能有助于了解他们如何使用ruby处理git钩子。

我建议您看看gitorious()。 他们使用ssh来处理身份验证和权限管理(获取ssh提供的用户名)。
他们在git存储库上也有一些钩子。我想这可能有助于了解他们如何使用ruby处理git钩子。

当更新钩子触发时,服务器有了新的提交:问题是钩子是否允许有问题的引用移动。您需要本地(发送)存储库中的哪些信息

对于凭据问题,请通过单个用户向每个人发送消息。例如,GitHub对git用户执行此操作,这就是为什么他们的SSH URL以
git@github.com:…
。然后在
~git/.ssh/authorized_keys
中,将用户名与每个密钥相关联。请注意,以下内容应放在一行上,但出于演示目的而进行了包装

no-agent-forwarding,no-port-forwarding,no-pty,no-X11-forwarding, command="env myuser=gbgcoll /usr/bin/git-shell -c \"${SSH_ORIGINAL_COMMAND:-}\"" ssh-rsa AAAAB... 无代理转发,无端口转发,无pty,无X11转发, command=“env myuser=gbgcoll/usr/bin/git shell-c\”${SSH\u ORIGINAL\u command:-}” ssh rsa AAAAB。。。 现在要查看谁在尝试更新,钩子将检查
$myuser
环境变量


这不会为您提供每个用户的Jira凭据。要解决这个问题,请创建一个对所有内容都具有只读访问权限的虚拟Jira帐户,并在钩子中硬编码该Jira帐户的凭据。这允许您验证给定的PR是否存在。

当您的更新钩子触发时,服务器有了新的提交:问题是钩子是否允许相关的引用移动。您需要本地(发送)存储库中的哪些信息

对于凭据问题,请通过单个用户向每个人发送消息。例如,GitHub对git用户执行此操作,这就是为什么他们的SSH URL以
git@github.com:…
。然后在
~git/.ssh/authorized_keys
中,将用户名与每个密钥相关联。请注意,以下内容应放在一行上,但出于演示目的而进行了包装

no-agent-forwarding,no-port-forwarding,no-pty,no-X11-forwarding, command="env myuser=gbgcoll /usr/bin/git-shell -c \"${SSH_ORIGINAL_COMMAND:-}\"" ssh-rsa AAAAB... 无代理转发,无端口转发,无pty,无X11转发, command=“env myuser=gbgcoll/usr/bin/git shell-c\”${SSH\u ORIGINAL\u command:-}” ssh rsa AAAAB。。。 现在要查看谁在尝试更新,钩子将检查
$myuser
环境变量


这不会为您提供每个用户的Jira凭据。要解决这个问题,请创建一个对所有内容都具有只读访问权限的虚拟Jira帐户,并在钩子中硬编码该Jira帐户的凭据。这允许您验证给定的PR是否存在。

您的具体问题是什么?我无法从本地git回购获得信息。或者在我调用git push origin master命令后,从用户那里。您将此脚本连接到哪个钩子?@robert its on the update hook您的具体问题是什么?我无法从本地git repo获取信息。或者在我调用git push origin master命令后,从用户那里。您将此脚本连接到哪个钩子?@robertits在更新钩子上