def get_comments(phid, author_phids, exclude_author_phid, days=None): phab = Phabricator() constraints = { 'authorPHIDs': author_phids, } transactions = phab.transaction.search( objectIdentifier='D%s' % phid, constraints=constraints, ) comments = [] for transaction in transactions.get('data'): if not transaction.get('comments'): continue created = transaction.get('comments')[0].get('dateCreated') if days and created < get_epoc_days_ago(days): continue author_phid = transaction.get('authorPHID') if author_phid == exclude_author_phid: continue comments.append({ 'authorPHID': author_phid, 'comments': transaction.get('comments')[0].get('content').get('raw'), }) list.reverse(comments) return comments
def __init__(self, config): self.config = config self.phab = Phabricator(host=config.phabricator_url, token=config.phabricator_token) self.phab.connect() self.phab.update_interfaces() self.instance_string = config.phabricator_revision_url
def get_task(version): p = Phabricator() constraints = { 'query': 'title:"{} deployment blockers"'.format(version) } phid = p.maniphest.search(constraints=constraints)['data'][0]['id'] return 'https://phabricator.wikimedia.org/T{}'.format(phid)
def loadConfig(): global PuppetRoot global PhabricatorAPIToken global PhabricatorHost global WireguardManifestFilePath global RepositoryName global RepositoryCommit global PHIDsOfProjectsToNotify click.echo('Loading config...') config = configparser.ConfigParser() config.read('config.ini') params = config['Params'] PuppetRoot = params['puppet_root'] PhabricatorAPIToken = params['phabricator_api_token'] PhabricatorHost = params['phabricator_host'] WireguardManifestFilePath = params['wireguard_manifest_file_path'] RepositoryName = params['puppet_repository_name'] RepositoryCommit = params['puppet_repository_commit'] projects = config['Projects_To_Tag'] PHIDsOfProjectsToNotify = [projects[slug] for slug in projects.keys()] repo = git.Repo(PuppetRoot) phab = Phabricator(host=PhabricatorHost, token=PhabricatorAPIToken) return (repo, phab)
def __init__(self): # Get super-early debugging by `export PHABFIVE_DEBUG=1` if "PHABFIVE_DEBUG" in os.environ: log.setLevel(logging.DEBUG) log.info("Loglevel is: {}".format( logging.getLevelName(log.getEffectiveLevel()))) self.conf = self.load_config() maxlen = 8 + len(max(dict(self.conf).keys(), key=len)) for k, v in dict(self.conf).items(): log.debug("{} {} {}".format(k, "." * (maxlen - len(k)), v)) # check for required configurables for k, v in dict(self.conf).items(): if k in REQUIRED and not v: error = "{} is not configured".format(k) example = CONFIG_EXAMPLES.get(k) if example: error += ", " + example raise PhabfiveConfigException(error) # check validity of configurables for k in VALIDATORS.keys(): if not re.match(VALIDATORS[k], self.conf[k]): error = "{} is malformed".format(k) example = VALID_EXAMPLES.get(k) if example: error += ", " + example raise PhabfiveConfigException(error) self.phab = Phabricator(host=self.conf.get("PHAB_URL"), token=self.conf.get("PHAB_TOKEN")) self.verify_connection()
def init(): global phab, tag_map phab = Phabricator(host=os.environ['PHABRICATOR_API_URL'], token=os.environ.get('PHABRICATOR_API_TOKEN')) phab.update_interfaces() tag_map = task_tagger.resolve_tags(phab)
def get_phabricator_client(): """Return a Phabricator client instance""" client = Phabricator(username='******', token='<%= @icingabot_password %>', host='https://phabricator.miraheze.org/api/') return client
def __init__(self, config): self.running = True self.timer_in_seconds = config['phabricator']['listener']['interval'] self.latest = None self.phab = Phabricator(host='https://phabricator.services.mozilla.com/api/', token=config['phabricator']['token']) self.phab.update_interfaces()
def setup_phab(projectphid): phab = Phabricator() phab.update_interfaces() print "Fetching tasks from Phab" tasks = phab.maniphest.query(projectPHIDs=[projectphid], status="status-open", limit=3000) return (phab, tasks)
def test_author_data_full(self): phab = Phabricator(host='dummmy.com', token='dummy.token') response, raw_response = PhabricatorService().author_data( author_phid="PHID-USER-test", raw_response=test_mock.mock_phabricator_raw_response(), phab=phab) print(response) self.assertTrue(True, False)
def __init__(self, token: Optional[str], host: Optional[str] = 'https://reviews.llvm.org/api/', dry_run_updates: bool = False): self._phab = None # type: Optional[Phabricator] self.dry_run_updates = dry_run_updates self._phab = Phabricator(token=token, host=host) self.update_interfaces()
def test_resolve_tags__should_find_standard_tags(): phab = Phabricator(host=os.environ['PHABRICATOR_API_URL'], token=os.environ.get('PHABRICATOR_API_TOKEN')) tag_map = resolve_tags(phab) eq_(tag_map['has_revision_required_diff_tag'], "PHID-PROJ-kx4rkibaeu6rt72oupll") eq_(tag_map['has_diff_tag'], "PHID-PROJ-segawqxql2j3qedl7cqc") eq_(tag_map['has_accepted_diff_tag'], "PHID-PROJ-72kxzxxqoak5bp2llx3m")
def test_get_diff(): phab = Phabricator(host=api_url_base, token=credentials.api_key) response = phab.differential.getdiff(diff_id="178") parsed = response.__dict__ filename = 'diff.json' if filename: with open(filename, 'r') as f: data = json.load(f) assert parsed == data
def test_get_last_comment(self, mock_phabricator_author_data): phab = Phabricator(host='dummy.com', token='dummy.token') comments = test_mock.mock_phabricator_get_comments(1201, phab) response = PhabricatorService().get_last_comment(comments, phab, raw_response=[]) createdAt = datetime.datetime.fromtimestamp(float(1551763640)) res = LastComment(author='dummy_user', body='This is some content', created_at=createdAt) self.assertEqual(response, res)
def phid_to_name(phid): if phid is None: return None if cache.has(phid): return cache.get(phid) phab = Phabricator() data = phab.phid.lookup(names=[ phid, ]) name = data[phid]['name'] cache.set(phid, name) return name
def get_phabricator_client(): """Return a Phabricator client instance""" parser = ConfigParser.SafeConfigParser() parser_mode = 'phabricator_bot' parser.read(PHABRICATOR_CONFIG_FILE) client = Phabricator(username=parser.get(parser_mode, 'username'), token=parser.get(parser_mode, 'token'), host=parser.get(parser_mode, 'host')) return client
def test_get_raw_diff(): phab = Phabricator(host=api_url_base, token=credentials.api_key) response = phab.differential.getrawdiff(diffID="178") parsed = response.__dict__ with open('rawdiff.json', 'w') as outfile: json.dump(parsed, outfile) filename = 'rawdiff.json' if filename: with open(filename, 'r') as f: data = json.load(f) assert parsed == data
def __init__(self, version, crs): self.version = version self.crs = crs self.last_five_version_ids = None self.version = version phab = Phabricator() self.train_blocker = trainblockers.TrainBlockers(self.version, phab) try: self.conductor = trainblockers.get_phab_user( self.train_blocker.blocker_task['fields']['ownerPHID'], phab) except APIError: self.conductor = 'Release Engineer Team' backups = self.train_blocker.blocker_task['fields'][ 'custom.train.backup'] if backups: self.backup = trainblockers.get_phab_user(backups[0], phab) else: self.backup = 'Nobody .·´¯`(>▂<)´¯`·.' self.stats = TrainsStats( self.crs.execute( ''' SELECT id, version, patches, rollbacks, (group0_delay_days + group1_delay_days + group2_delay_days) as days_delay, (SELECT count(*) from blocker b WHERE b.train_id = train.id) as blocker_count FROM train WHERE start_time <= ( SELECT start_time FROM train WHERE version = ? ) ORDER BY start_time desc LIMIT 5 ''', (self.version, )).fetchall()) self.thanks = set() for row in self.crs.execute( ''' SELECT blocker, unblocker FROM train t JOIN blocker b ON b.train_id = t.id WHERE version = ? ''', (self.version, )).fetchall(): if row[0] not in [self.conductor, self.backup, 'null']: self.thanks.add(row[0]) if row[1] not in [self.conductor, self.backup, 'null']: self.thanks.add(row[1])
def main(args): parser = argparse.ArgumentParser(prog=args[0], add_help=True, usage='%(prog)s [script] [reports...]', description=__doc__) parser.add_argument('--no-report', action='store_true', help='Do not report test results to phabricator') parser.add_argument('script', type=str, help='script to execute') parser.add_argument('reports', type=str, nargs='*', help='list of test result files') parsed = parser.parse_args(args[1:]) token = os.environ.get("TEAMCITY_CONDUIT_TOKEN", None) if not token and not parsed.no_report: print("Please provide a conduit token in the environment variable ""TEAMCITY_CONDUIT_TOKEN""") sys.exit(1) arcconfig = get_arcconfig() phabricatorUrl = urlparse.urljoin(arcconfig['conduit_uri'], "api/") buildUrl = os.environ.get('BUILD_URL', '') failures, exitcode = execute_and_parse(parsed.script) for file in parsed.reports: # All inputs may not exist if the build fails prematurely if not os.path.isfile(file): continue elif file.endswith(".xml"): failures.update(get_failures(file)) build_status = "success" if len(failures) != 0: build_status = "failure" if len(failures) != 0 and exitcode == 0: exitcode = 1 if parsed.no_report: print("Build terminated with {}".format(build_status)) sys.exit(exitcode) phab = Phabricator(host=phabricatorUrl, token=token) phab.update_interfaces() revisionID = get_revision(phab, get_commit_message()) authorPHID = get_author(phab, revisionID) if build_status != "success": task_body = create_task_body(buildUrl, revisionID, failures) create_task(phab, authorPHID, revisionID, task_body) create_comment(phab, revisionID, build_status, buildUrl) sys.exit(exitcode)
def test_get_reviews_no_raw(self, mock_get_comments, mock_phabricator_get_last_comment, mock_phabricator_author_data, mock_phabricator_time_from_epoch): reviews = test_mock.mock_phabricator_differential_query( None, None, None) phab = Phabricator(host='dummmy.com', token='dummy.token') response = PhabricatorService().get_reviews(phab, reviews, host="www.google.com", raw_response=[]) self.assertEqual(response[0]._format_oneline(1, 1), self.config['msg2'])
def get_diffs(author_phids, days=None): phab = Phabricator() constraints = { 'authorPHIDs': author_phids, } if settings.DIFF_STATUS: constraints['statuses'] = settings.DIFF_STATUS if days: constraints['createdStart'] = get_epoc_days_ago(days) results = phab.differential.revision.search(constraints=constraints, #order='newest', ) return results.get('data')
def get_phabricator_client(): """Return a Phabricator client instance.""" parser = ConfigParser.SafeConfigParser() parser_mode = 'phabricator_bot' parser.read(PHABRICATOR_CONFIG_FILE) host = parser.get(parser_mode, 'host') username = parser.get(parser_mode, 'username') client = Phabricator( host=host, username=username, token=parser.get(parser_mode, 'token')) logger.debug(("Initialized Phabricator client with host '{host}' and " "username '{user}'").format(host=host, user=username)) return client
def __init__(self, comment_file_path: str, git_hash: str): # TODO: turn os.environ parameter into command line arguments # this would be much clearer and easier for testing self.comment_file_path = comment_file_path self.conduit_token = os.environ.get('CONDUIT_TOKEN') # type: Optional[str] self.host = os.environ.get('PHABRICATOR_HOST') # type: Optional[str] self._load_arcrc() self.diff_id = os.environ['DIFF_ID'] # type: str self.diff_json_path = os.environ['DIFF_JSON'] # type: str if not self.host.endswith('/api/'): self.host += '/api/' self.phab = Phabricator(token=self.conduit_token, host=self.host) self.git_hash = git_hash # type: Optional[str] self.msg = [] # type: List[str]
def test_on_task_update__for_task_with_needs_changes_diff__should_remove_undesired_tags( cassette): phab = Phabricator(host=os.environ['PHABRICATOR_API_URL'], token=os.environ.get('PHABRICATOR_API_TOKEN')) tag_map = resolve_tags(phab) on_task_update(phab, 2895, tag_map=tag_map) eq_(cassette.requests[-1].url, "https://truecode.trueship.com/api/maniphest.edit") eq_( cassette.requests[-1].body, b"params=%7B%22objectIdentifier%22%3A+%22PHID-TASK-bdaz2w2ue4nlotls6wqn%22%2C+%22transactions%22%3A+%5B%7B%22value%22%3A+%5B%22PHID-PROJ-kx4rkibaeu6rt72oupll%22%5D%2C+%22type%22%3A+%22projects.add%22%7D%2C+%7B%22value%22%3A+%5B%22PHID-PROJ-segawqxql2j3qedl7cqc%22%2C+%22PHID-PROJ-72kxzxxqoak5bp2llx3m%22%5D%2C+%22type%22%3A+%22projects.remove%22%7D%5D%2C+%22__conduit__%22%3A+%7B%22token%22%3A+%22123%22%7D%7D&output=json" )
def test_on_task_update__for_task_with_unreviewed_diff__should_tag_with_diff_tag( cassette): phab = Phabricator(host=os.environ['PHABRICATOR_API_URL'], token=os.environ.get('PHABRICATOR_API_TOKEN')) tag_map = resolve_tags(phab) on_task_update(phab, 3109, tag_map=tag_map) eq_(cassette.requests[-1].url, "https://truecode.trueship.com/api/maniphest.edit") eq_( cassette.requests[-1].body, b"params=%7B%22transactions%22%3A+%5B%7B%22value%22%3A+%5B%22PHID-PROJ-segawqxql2j3qedl7cqc%22%5D%2C+%22type%22%3A+%22projects.add%22%7D%5D%2C+%22objectIdentifier%22%3A+%22PHID-TASK-s3scdbecgvk23b4uwsfp%22%2C+%22__conduit__%22%3A+%7B%22token%22%3A+%22123%22%7D%7D&output=json" )
def test_on_task_update__for_task_with_accepted_diff__should_tag_with_accepted_tag( cassette): phab = Phabricator(host=os.environ['PHABRICATOR_API_URL'], token=os.environ.get('PHABRICATOR_API_TOKEN')) tag_map = resolve_tags(phab) on_task_update(phab, 3070, tag_map=tag_map) eq_(cassette.requests[-1].url, "https://truecode.trueship.com/api/maniphest.edit") eq_( cassette.requests[-1].body, b"params=%7B%22objectIdentifier%22%3A+%22PHID-TASK-djleagj2aiegvb7kzivn%22%2C+%22__conduit__%22%3A+%7B%22token%22%3A+%22123%22%7D%2C+%22transactions%22%3A+%5B%7B%22value%22%3A+%5B%22PHID-PROJ-72kxzxxqoak5bp2llx3m%22%5D%2C+%22type%22%3A+%22projects.add%22%7D%5D%7D&output=json" )
def test_on_task_update__for_task_with_no_diff__should_remove_diff_tag( cassette): phab = Phabricator(host=os.environ['PHABRICATOR_API_URL'], token=os.environ.get('PHABRICATOR_API_TOKEN')) tag_map = resolve_tags(phab) on_task_update(phab, 3073, tag_map=tag_map) eq_(cassette.requests[-1].url, "https://truecode.trueship.com/api/maniphest.edit") eq_( cassette.requests[-1].body, b"output=json¶ms=%7B%22objectIdentifier%22%3A+%22PHID-TASK-6mh4up4avtz2wjr2a2sd%22%2C+%22transactions%22%3A+%5B%7B%22type%22%3A+%22projects.remove%22%2C+%22value%22%3A+%5B%22PHID-PROJ-segawqxql2j3qedl7cqc%22%5D%7D%5D%2C+%22__conduit__%22%3A+%7B%22token%22%3A+%22123%22%7D%7D" )
def test_on_task_update__for_landed_task_with_accepted_diff__should_tag_with_accepted_tag( cassette): phab = Phabricator(host=os.environ['PHABRICATOR_API_URL'], token=os.environ.get('PHABRICATOR_API_TOKEN')) tag_map = resolve_tags(phab) on_task_update(phab, 3135, tag_map=tag_map) eq_(cassette.requests[-1].url, "https://truecode.trueship.com/api/maniphest.edit") eq_( cassette.requests[-1].body, b"output=json¶ms=%7B%22transactions%22%3A+%5B%7B%22type%22%3A+%22projects.add%22%2C+%22value%22%3A+%5B%22PHID-PROJ-t2mvgyqoolxpakgeyngn%22%5D%7D%2C+%7B%22type%22%3A+%22projects.remove%22%2C+%22value%22%3A+%5B%22PHID-PROJ-segawqxql2j3qedl7cqc%22%5D%7D%5D%2C+%22__conduit__%22%3A+%7B%22token%22%3A+%22123%22%7D%2C+%22objectIdentifier%22%3A+%22PHID-TASK-zjxys23b7zuuojohnfrl%22%7D" )
async def phabricator_message(tag, message: discord.Message): tags = split_bz(tag) phab = Phabricator() revision = phab.api.differential.getrevision(revision_id=int(tags[1])) author = phab.api.user.query(phids=[revision.authorPHID])[0] summary = "" summary += "<https://phabricator.kde.org/D{}>\n".format(tags[1]) summary += "> **{}** ({}) - D{}\n".format(author["realName"], author["userName"], tags[1]) summary += "> Status - {}\n".format(revision.statusName) summary += "> \n" summary += "> {}".format(revision.title) await message.channel.send(summary)
def phab(*args, **kwargs): """ { u'userName': u's.trofimov', u'primaryEmail': u'*****@*****.**', u'phid': u'PHID-USER-3ipdpoxtzw4wdlkea4w7', u'realName': u'Sergey Trofimov', u'roles': [u'admin', u'verified', u'approved', u'activated'], u'image': u'http://phabricator.corp.mail.ru/file/data/mrwzwutqaolpy5zqji6e/PHID-FILE-pemgj2dhdbwmlffi3j7s/profile', u'uri': u'http://phabricator.corp.mail.ru/p/s.trofimov/' } """ from phabricator import Phabricator phab = Phabricator() # This will use your ~/.arcrc file me = phab.user.whoami() import ipdb; ipdb.set_trace()