def initialize_github(self): """Initialize github data. """ configuration = self.git.get_configuration("github") token = configuration.get("token") if token and not self.namespace.new: token = prompt(MESSAGES["github_token"], token) else: user = prompt(MESSAGES["github_user"], configuration.get("user")) password = prompt(MESSAGES["github_password"], echo=False) name = "continuity:{0}".format(self.git.repo.working_dir) url = "https://github.com/jzempel/continuity" try: token = GitHubService.create_token(user, password, name, url=url) except GitHubRequestException: code = prompt(MESSAGES["github_2fa_code"]) token = GitHubService.create_token(user, password, name, code=code, url=url) if not token: exit("Invalid GitHub credentials.") return {"token": token}
def execute(self): """Execute this init command. """ puts("Enter values or accept [defaults] with Enter.") puts() self.continuity = self.initialize_continuity() if self.continuity["tracker"] == "jira": puts() self.jira = self.initialize_jira() elif self.continuity["tracker"] == "pivotal": puts() self.pivotal = self.initialize_pivotal() puts() self.github = self.initialize_github() self.aliases = {} commands = get_commands(self.continuity["tracker"]) for command, command_class in commands.iteritems(): if issubclass(command_class, GitCommand): alias = "continuity" if command == "init" else command self.aliases[alias] = "!continuity {0}".format(command) self.git.set_configuration("continuity", **self.continuity) self.git.set_configuration("github", **self.github) self.git.set_configuration("jira", **self.jira) self.git.set_configuration("pivotal", **self.pivotal) self.git.set_configuration("alias", **self.aliases) if self.pivotal: github = GitHubService(self.git, self.github["token"]) hooks = github.get_hooks() if hooks is not None: token = hooks.get("pivotaltracker", {}).get("config", {}).\ get("token") if not token: token = self.pivotal["api-token"] github.create_hook("pivotaltracker", token=token) filename = "{0}/hooks/prepare-commit-msg".format(self.git.repo.git_dir) if exists(filename): backup = "{0}.bak".format(filename) if not exists(backup): rename(filename, backup) with open(filename, 'w') as hook: hook.write('#!/bin/sh\n\ncontinuity commit "$@"') chmod(filename, 0755)
def initialize_github(self): """Initialize github data. """ configuration = self.git.get_configuration("github") token = configuration.get("oauth-token") if token and not self.namespace.new: token = prompt("GitHub OAuth token", token) else: user = prompt("GitHub user", configuration.get("user")) password = getpass("GitHub password: "******"continuity:{0}".format(self.git.repo.working_dir) url = "https://github.com/jzempel/continuity" token = GitHubService.create_token(user, password, name, url) if not token: exit("Invalid GitHub credentials.") return {"oauth-token": token}