def getUserRepositoryCommit(userID, arrayRepository, numPage=100): arrayCommits = [] for index, repository in enumerate(arrayRepository): owner, name = repository['nameWithOwner'].split('/') if name == "linux": 'Ignorou repositorio linux por nao retornar o historico via api' continue queryVariables = { "numPageIssues": numPage, "idUser": userID, "owner": owner, "name": name } query = getQueryFile('userRepositoryCommit') while True: resp = requestApiGitHubV4(query, queryVariables) if not resp['data']['repository']['defaultBranchRef'] or \ resp['data']['repository']['defaultBranchRef']['target']['history']['totalCount'] == 0: break resp = resp['data']['repository']['defaultBranchRef']['target'][ 'history'] for number, commit in enumerate(resp['nodes']): arrayCommits.append(commit) if not resp['pageInfo']['hasNextPage']: break query = getQueryFile('userRepositoryCommitNext') queryVariables["after"] = resp['pageInfo']['endCursor'] return arrayCommits
def getUserInfByYear(loginUser, dateCreated): dateCreated = dateCreated.split("-") yearCreated = int(dateCreated[0]) todayDate = str(date.today()).split('-') todayYear = int(todayDate[0]) userYearInfo = {} inManyYears = todayYear - yearCreated while yearCreated <= todayYear: yearCreated = yearCreated queryVariables = { "nameUser": loginUser, "fromDate": '{}-01-01T04:00:00Z'.format(yearCreated), "toDate": '{}-12-31T23:59:59Z'.format(yearCreated), } query = getQueryFile('userInfoContributionsCollection') resp = requestApiGitHubV4(query, queryVariables) if not resp['data']['user']["contributionsCollection"]: print("\n\n", resp, "\n\n") userYearInfo[yearCreated] = resp['data']['user'][ "contributionsCollection"] print('{}: {}'.format(yearCreated, list(userYearInfo[yearCreated].values()))) keys = userYearInfo[yearCreated].keys() yearCreated += 1 # fazer aki divisao return userYearInfo, keys, inManyYears
def getUserInfByMonth(loginUser, dateCreated): dateCreated = dateCreated.split("-") yearCreated = int(dateCreated[0]) monthCreated = int(dateCreated[1]) flagMonth = True todayDate = str(date.today()).split('-') todayYear = int(todayDate[0]) todayMonth = int(todayDate[1]) userYearInfo = {} while yearCreated <= todayYear: yearCreated = yearCreated if flagMonth: month = monthCreated flagMonth = False else: month = 1 userMonthInfo = {} while True: if month > 12 or (yearCreated == todayYear and month > todayMonth): break monthAux = str(month) monthAux = (str(0) + monthAux) if month < 10 else monthAux queryVariables = { "nameUser": loginUser, "fromDate": '{}-{}-01T04:00:00Z'.format(yearCreated, monthAux), "toDate": '{}-{}-31T23:59:59Z'.format(yearCreated, monthAux), } query = getQueryFile('userInfoContributionsCollection') userMonthInfo[month] = requestApiGitHubV4( query, queryVariables)['data']['user']["contributionsCollection"] print('{}/{}: {}'.format(yearCreated, month, list(userMonthInfo[month].values()))) userYearInfo['{}/{}'.format(yearCreated, month)] = list( userMonthInfo[month].values()) keys = userMonthInfo[month].keys() month += 1 yearCreated += 1 return userYearInfo, list(keys)
def repositoryUser(loginUser, numPage=80): queryVariables = {"nameUser": loginUser, "numPage": numPage} repositoryAffiliation = {'OWNER': [], 'COLLABORATOR': []} for repAff in repositoryAffiliation.keys(): queryVariables["RepositoryAffiliation"] = repAff query = getQueryFile('repositoryInfo') while True: resp = requestApiGitHubV4(query, queryVariables) for rep in resp['data']['user']['repositories']['nodes']: repositoryAffiliation[repAff].append(rep) if not resp['data']['user']['repositories']['pageInfo'][ 'hasNextPage']: break query = getQueryFile('repositoryInfNext') queryVariables["after"] = resp['data']['user']['repositories'][ 'pageInfo']['endCursor'] return repositoryAffiliation['OWNER'], repositoryAffiliation[ 'COLLABORATOR']
def getUserInfByYear(loginUser, dateCreated): dateCreated = dateCreated.split("-") yearCreated = int(dateCreated[0]) todayDate = str(date.today()).split('-') todayYear = int(todayDate[0]) userYearInfo = {} while yearCreated <= todayYear: yearCreated = yearCreated queryVariables = { "nameUser": loginUser, "fromDate": '{}-01-01T04:00:00Z'.format(yearCreated), "toDate": '{}-12-31T23:59:59Z'.format(yearCreated), } query = getQueryFile('userInfoContributionsCollection') userYearInfo[yearCreated] = requestApiGitHubV4( query, queryVariables)['data']['user']["contributionsCollection"] keys = userYearInfo[yearCreated].keys() yearCreated += 1 return userYearInfo, keys
def getUserInfo(usuerName): query = getQueryFile('userInformation') queryVariables = {'nameUser': usuerName} return requestApiGitHubV4(query, queryVariables)