0
我有一個Python腳本,民調GitHub的倉庫中引入請求和查找提交和更改的文件等於其他腳本爲1的Python 3.5:傳遞GitHub的憑據到另一個python腳本
一切似乎是工作除非我在第二個腳本運行時被提示輸入GitHub憑據。
我想通過gh
變量,它將主腳本中存儲庫的憑證保存到第二個腳本中,以便不必再次輸入憑證。
repo
和user
變量似乎正確傳遞給第二個腳本。
請參閱下面的代碼,並預先感謝您的任何指導。
main_en_pr腳本:
#! /usr/bin/python
import os
import github3
from github3 import login, GitHub, authorize
from getpass import getuser, getpass
import requests
import csv
import configparser
import sys
import codecs
sys.__stdout__ = codecs.getwriter('utf8')(sys.stdout)
# authenticate to GIT
try:
import readline
except ImportError:
pass
try:
user = input('GitHub username: ')
except KeyboardInterrupt:
user = getuser()
password = getpass('GitHub token for {0}: '.format(user))
gh = login(user, password)
# read the contents of the config file to pull in the repo name
config = configparser.ConfigParser()
config.read('repo.ini')
repo = config.get('repos', 'repo1')
# repo = input("Please enter your repo name: ")
result = gh.repository(user, repo).pull_requests('open')
def list_all_prs():
# open csv file and create header rows
with open('\\\\share\\pull.csv', 'w+', newline='') as f:
csv_writer = csv.writer(f)
csv_writer.writerow(['Id', 'Login', 'Title', 'Commits', 'Changed Files'])
# iterate through repo for pull requests based on criteria and output to csv file
for pr in result:
data = pr.as_dict()
changes = (gh.repository(user, repo).pull_request(data['number'])).as_dict()
# keep print to console statement for testing purposes
# print(changes['id'], changes['user']['login'], changes['title'], changes['commits'], changes['changed_files'])
with open('\\\\share\\pull.csv','a+',newline='') as f:
csv_writer = csv.writer(f)
csv_writer.writerow([changes['id'], changes['user']['login'], changes['title'], changes['commits'],
changes['changed_files']])
list_all_prs()
exec(open("one_commit_one_file_change.py").read())
one_commit_one_file_change腳本:
#! /usr/bin/python
import os
import github3
# from github3 import login, GitHub, authorize
# from getpass import getuser, getpass
import requests
import csv
import configparser
import sys
import main_en_pr
import codecs
sys.__stdout__ = codecs.getwriter('utf8')(sys.stdout)
def one_commit_one_file_change_pr():
#open csv file and create header rows
with open('\\\\share\\commit_filechange.csv', 'w+') as f:
csv_writer = csv.writer(f)
csv_writer.writerow(['Login', 'Title', 'Commits', 'Changed Files','Deletions', 'Additions'])
#iterate through repo for pull requests based on criteria and output to csv file
for pr in main_en_pr.result:
data = pr.as_dict()
changes = (main_en_pr.gh.repository(main_en_pr.user, main_en_pr.repo).pull_request(data['number'])).as_dict()
if changes['commits'] == 1 and changes['changed_files'] == 1:
#keep print to console statement for testing purposes
#print changes['user']['login']
with open('\\\\share\\commit_filechange.csv', 'a+') as f:
csv_writer = csv.writer(f)
csv_writer.writerow([changes['user']['login'], changes['title'], changes['commits'], changes['changed_files']])
one_commit_one_file_change_pr()
@Gaurav ...感謝您的評論。我還是新來的python。你有什麼好的文檔可以讓我指導一個好的教程嗎?我要自己去搜索,但是它也不會受到傷害:) – DBS