def zendesk_json_request(domain, api_path, attribute_name, request_type, json_params): oauth_token = git.config('%s.token' % domain) if oauth_token == '': oauth_token = None if oauth_token is None: auth_headers = {} else: auth_headers = {'Authorization': 'Bearer %s' % oauth_token} url = 'https://%s/api/v2%s' % (domain, api_path) if request_type == 'POST': r = session.post(url, headers=auth_headers, json=json_params) elif request_type == 'PUT': r = session.put(url, headers=auth_headers, json=json_params) elif request_type == 'GET' and json_params is None: r = session.get(url, headers=auth_headers) else: return None api_result = json.loads(r.text) if attribute_name in api_result: return api_result[attribute_name] else: print(r.text) return None
def zendesk_json_request(domain, api_path, attribute_name, request_type, json_params): auth_headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer %s' % git.config('%s.token' % domain) } url = 'https://%s/api/v2%s' % (domain, api_path) logging.info(url) if request_type == 'POST': r = session.post(url, headers=auth_headers, json=json_params) elif request_type == 'PUT': r = session.put(url, headers=auth_headers, json=json_params) elif request_type == 'GET' and json_params is None: r = session.get(url, headers=auth_headers) else: return None try: api_result = json.loads(r.text) except: print('%d, %s' % (r.status_code, r.text)) return None if attribute_name in api_result: return api_result[attribute_name] if 'error' in api_result and api_result['error'] == 'RecordNotFound': return None print('%d, %s' % (r.status_code, r.text)) exit()
def check(args): autocrlf = git.config('core.autocrlf') or 'false' if os.name == 'nt' and autocrlf != 'true': print('core.autocrlf: I recommend to set core.autocrlf=true on Windows (you have "{}")'.format(autocrlf)) elif os.name != 'nt' and autocrlf != 'input': print('core.autocrlf: I recommend to set core.autocrlf=input on Unix platforms (you have "{}")'.format(autocrlf)) else: print('core.autocrlf: Lookin\' good.')
def crowdin_request(repository, api_path, request_type='GET', data=None, files=None): headers = {'user-agent': 'python'} if repository is None: request_url = crowdin_base_url + api_path else: request_url = crowdin_base_url + '/project/' + repository.crowdin.project_name + api_path if repository is None: get_data = { 'login': git.config('crowdin.account-login'), 'account-key': git.config('crowdin.account-key-v1') } else: get_data = {'key': repository.crowdin.api_key} if request_type == 'GET': if data is not None: get_data.update(data) request_url = request_url + '?' + '&'.join( [key + '=' + value for key, value in get_data.items()]) r = requests.get(request_url, data=get_data, headers=headers) else: request_url = request_url + '?' + '&'.join( [key + '=' + value for key, value in get_data.items()]) r = requests.post(request_url, data=data, files=files, headers=headers) if r.status_code < 200 or r.status_code >= 400: logging.error('HTTP Error: %d' % r.status_code) return (r.status_code, None) return (r.status_code, r.content)
def get_zendesk_article_content(domain, article_id): oauth_token = git.config('%s.token' % domain) if oauth_token == '': oauth_token = None if oauth_token is None: return None article = zendesk_json_request( domain, '/help_center/en-us/articles/%s.json' % article_id, 'article', 'GET', None) if article is None: return None return article['body']
def test_config(self): import util _old_run = util.run def mock_run(*args): print args if args == ('git', 'config', '--list'): return _old_run('echo', 'user.name=foo\[email protected]') else: return _old_run(*args) util.run = mock_run config = git.config() self.assertEqual(config.get('user.name'), 'foo') self.assertEqual(config.get('user.email'), '*****@*****.**') util.run = _old_run
def get_jira_cookie(): jira_cookie = None jira_cookie_name = None jira_cookie_value = None try: jira_cookie_name = git.config('jira.session-cookie-name') jira_cookie_value = git.config('jira.session-cookie-value') except: pass if jira_cookie_name == '': jira_cookie_name = None if jira_cookie_value == '': jira_cookie_value = None if jira_cookie_name is not None and jira_cookie_value is not None: jira_cookie = {jira_cookie_name: jira_cookie_value} r = requests.get(jira_base_url + '/auth/1/session', cookies=jira_cookie) if r.status_code != 200: jira_cookie = None if jira_cookie is not None: return jira_cookie if jira_username is None or jira_password is None: return None post_json = {'username': jira_username, 'password': jira_password} r = requests.post(jira_base_url + '/rest/auth/1/session', json=post_json) if r.status_code != 200: print('Invalid login') return None response_json = r.json() jira_cookie_name = response_json['session']['name'] jira_cookie_value = response_json['session']['value'] git.config('--global', 'jira.session-cookie-name', jira_cookie_name) git.config('--global', 'jira.session-cookie-value', jira_cookie_value) jira_cookie = {jira_cookie_name: jira_cookie_value} return jira_cookie
from os.path import abspath, dirname, isdir, isfile, join, relpath import re import requests import sys from tqdm import tqdm try: from urllib import parse except: import urlparse as parse sys.path.insert( 0, dirname(dirname(abspath(inspect.getfile(inspect.currentframe()))))) import git username = git.config('files.username') password = git.config('files.password') json_auth_token = {} session = requests.session() def get_namespaced_parameters(portlet_id, parameters): return {('_%s_%s' % (portlet_id, key)): value for key, value in parameters.items()} def authenticate(base_url, get_params=None): r = session.get(base_url, data=get_params) if r.url.find('https://login.liferay.com/') == 0:
version = re.sub('refs/tags/', '', os.environ['GITHUB_REF']) # login github = Github(os.environ['API_CREDENTIALS']) print(INFO + "Cloning repo." + ENDC) clone_from = "https://" \ + os.environ['GITHUB_ACTOR'] \ + ":" \ + os.environ['API_CREDENTIALS'] \ + "@github.com/" \ + repository git = git.Repo.clone_from(clone_from, '.').git print(INFO + "Setting up git configuration." + ENDC) git.config('--global', 'user.name', os.environ['INPUT_GIT_USER_NAME']) git.config('--global', 'user.email', os.environ['INPUT_GIT_USER_EMAIL']) git.config('--global', 'branch.autosetuprebase', 'always') # what to find and what to replace it with subs = [ (fr'docker://{repository}:\d+\.\d+\.\d+', f'docker://{repository}:{version}'), (fr'{repository}@\d+\.\d+\.\d+', f'{repository}@{version}'), (fr'corral add github.com/{repository}.git -(-version|v) \d+\.\d+\.\d+', fr'corral add github.com/{repository}.git -\1 {version}') ] # find the README readme_file_options = ["README.md", "README.rst"]
from datetime import datetime from file_manager import get_crowdin_file, get_root_folders import git import json import logging import os import requests from repository import initial_dir from scrape_liferay import authenticate, session import time github_oauth_token = git.config('github.oauth-token') assert (github_oauth_token is not None) github_base_url = 'https://api.github.com' def github_request(api_path, request_type=None, data=None): headers = { 'user-agent': 'python', 'authorization': 'token %s' % github_oauth_token, 'accept': 'application/vnd.github.inertia-preview+json' } logging.info('github-api %s' % api_path) if data is None: r = requests.get(github_base_url + api_path, headers=headers) elif request_type == 'PATCH': r = requests.patch(github_base_url + api_path, json=data,
if not external_url.endswith('/'): external_url += '/' as_html = removed.replace('.md', '') link = external_url + as_html + "/" line = line.replace(removed, link) fp.write(line) # # run mkdocs to actually build the content # print(INFO + "Setting up git configuration." + ENDC) git = git.Repo().git git.config('--global', 'user.name', os.environ['INPUT_GIT_USER_NAME']) git.config('--global', 'user.email', os.environ['INPUT_GIT_USER_EMAIL']) if deploy_key: @contextmanager def git_auth(): """ Temporarily set SSH credentials for Git. To be used as context manager. """ (ssh_wrapper_fd, ssh_wrapper_path) = mkstemp(text=True) try: with NamedTemporaryFile() as identity_file: with open(ssh_wrapper_fd, "w") as ssh_wrapper_file: ssh_wrapper_file.write('#!/bin/sh\n') ssh_wrapper_file.write( f'exec ssh -o StrictHostKeyChecking=no '
def getRepositoryUrl(repo): git = repo.git # Command to get URL for repository: (your_remote) # git config --get remote.origin.url remoteUrl = git.config('--get', 'remote.origin.url') return remoteUrl
import inspect from os.path import abspath, dirname import requests import sys sys.path.insert( 0, dirname(dirname(abspath(inspect.getfile(inspect.currentframe()))))) import git jira_base_url = 'https://issues.liferay.com' jira_username = git.config('jira.session-username') jira_password = git.config('jira.session-password') if jira_username == '': jira_username = None if jira_password == '': jira_password = None def get_jira_cookie(): jira_cookie = None jira_cookie_name = None jira_cookie_value = None try: jira_cookie_name = git.config('jira.session-cookie-name') jira_cookie_value = git.config('jira.session-cookie-value')
def crowdin_http_request(repository, path, method, **data): global csrf_token if method == 'GET': get_data = {key: value for key, value in data.items()} get_data['project_id'] = repository.crowdin.project_id get_data['target_language_id'] = '25' query_string = '&'.join([ urllib.parse.quote(key) + '=' + urllib.parse.quote(str(value)) for key, value in get_data.items() ]) url = 'https://crowdin.com%s?%s' % (path, query_string) else: url = 'https://crowdin.com%s' % path session.cookies.set('csrf_token', csrf_token, domain='.crowdin.com', path='/') try: if method == 'GET': r = session.get(url, headers={'x-csrf-token': csrf_token}) elif method == 'POST': r = session.post(url, data=data, headers={'x-csrf-token': csrf_token}) if r.url.find('/login') == -1: return r.content except: pass logging.info('Session timed out, refreshing session') continue_url = 'https://crowdin.com/%s/settings' % repository.crowdin.project_name login_url = 'https://accounts.crowdin.com/login' r = session.get(login_url) soup = BeautifulSoup(r.text, features='html.parser') token_input = soup.find('input', attrs={'name': '_token'}) if token_input is None: return crowdin_http_request(repository, path, method, **data) login_data = { 'email_or_login': git.config('crowdin.login'), 'password': git.config('crowdin.password'), 'hash': 'files', 'continue': url, 'locale': 'en', 'intended': '/auth/token', '_token': token_input.attrs['value'] } r = session.post(login_url, data=login_data) return crowdin_http_request(repository, path, method, **data)