The goal of this series is to make hg debugcallconduit work outside of a hg
repo.
This patch, removes requirement of repo object from readurltoken as we only need
ui there. It also updates the callers to pass in ui instead of repo.
| hg-reviewers |
The goal of this series is to make hg debugcallconduit work outside of a hg
repo.
This patch, removes requirement of repo object from readurltoken as we only need
ui there. It also updates the callers to pass in ui instead of repo.
| Automatic diff as part of commit; lint not applicable. |
| Automatic diff as part of commit; unit tests not applicable. |
| Path | Packages | |||
|---|---|---|---|---|
| M | hgext/phabricator.py (12 lines) |
| for k, v in items(obj): | for k, v in items(obj): | ||||
| if prefix: | if prefix: | ||||
| process(b'%s[%s]' % (prefix, k), v) | process(b'%s[%s]' % (prefix, k), v) | ||||
| else: | else: | ||||
| process(k, v) | process(k, v) | ||||
| process(b'', params) | process(b'', params) | ||||
| return util.urlreq.urlencode(flatparams) | return util.urlreq.urlencode(flatparams) | ||||
| def readurltoken(repo): | def readurltoken(ui): | ||||
| """return conduit url, token and make sure they exist | """return conduit url, token and make sure they exist | ||||
| Currently read from [auth] config section. In the future, it might | Currently read from [auth] config section. In the future, it might | ||||
| make sense to read from .arcconfig and .arcrc as well. | make sense to read from .arcconfig and .arcrc as well. | ||||
| """ | """ | ||||
| url = repo.ui.config(b'phabricator', b'url') | url = ui.config(b'phabricator', b'url') | ||||
| if not url: | if not url: | ||||
| raise error.Abort(_(b'config %s.%s is required') | raise error.Abort(_(b'config %s.%s is required') | ||||
| % (b'phabricator', b'url')) | % (b'phabricator', b'url')) | ||||
| res = httpconnectionmod.readauthforuri(repo.ui, url, util.url(url).user) | res = httpconnectionmod.readauthforuri(ui, url, util.url(url).user) | ||||
| token = None | token = None | ||||
| if res: | if res: | ||||
| group, auth = res | group, auth = res | ||||
| repo.ui.debug(b"using auth.%s.* for authentication\n" % group) | ui.debug(b"using auth.%s.* for authentication\n" % group) | ||||
| token = auth.get(b'phabtoken') | token = auth.get(b'phabtoken') | ||||
| if not token: | if not token: | ||||
| raise error.Abort(_(b'Can\'t find conduit token associated to %s') | raise error.Abort(_(b'Can\'t find conduit token associated to %s') | ||||
| % (url,)) | % (url,)) | ||||
| return url, token | return url, token | ||||
| def callconduit(repo, name, params): | def callconduit(repo, name, params): | ||||
| """call Conduit API, params is a dict. return json.loads result, or None""" | """call Conduit API, params is a dict. return json.loads result, or None""" | ||||
| host, token = readurltoken(repo) | host, token = readurltoken(repo.ui) | ||||
| url, authinfo = util.url(b'/'.join([host, b'api', name])).authinfo() | url, authinfo = util.url(b'/'.join([host, b'api', name])).authinfo() | ||||
| repo.ui.debug(b'Conduit Call: %s %s\n' % (url, pycompat.byterepr(params))) | repo.ui.debug(b'Conduit Call: %s %s\n' % (url, pycompat.byterepr(params))) | ||||
| params = params.copy() | params = params.copy() | ||||
| params[b'api.token'] = token | params[b'api.token'] = token | ||||
| data = urlencodenested(params) | data = urlencodenested(params) | ||||
| curlcmd = repo.ui.config(b'phabricator', b'curlcmd') | curlcmd = repo.ui.config(b'phabricator', b'curlcmd') | ||||
| if curlcmd: | if curlcmd: | ||||
| sin, sout = procutil.popen2(b'%s -d @- %s' | sin, sout = procutil.popen2(b'%s -d @- %s' | ||||
| # Map from "hg:meta" keys to header understood by "hg import". The order is | # Map from "hg:meta" keys to header understood by "hg import". The order is | ||||
| # consistent with "hg export" output. | # consistent with "hg export" output. | ||||
| _metanamemap = util.sortdict([(b'user', b'User'), (b'date', b'Date'), | _metanamemap = util.sortdict([(b'user', b'User'), (b'date', b'Date'), | ||||
| (b'branch', b'Branch'), (b'node', b'Node ID'), | (b'branch', b'Branch'), (b'node', b'Node ID'), | ||||
| (b'parent', b'Parent ')]) | (b'parent', b'Parent ')]) | ||||
| def _confirmbeforesend(repo, revs, oldmap): | def _confirmbeforesend(repo, revs, oldmap): | ||||
| url, token = readurltoken(repo) | url, token = readurltoken(repo.ui) | ||||
| ui = repo.ui | ui = repo.ui | ||||
| for rev in revs: | for rev in revs: | ||||
| ctx = repo[rev] | ctx = repo[rev] | ||||
| desc = ctx.description().splitlines()[0] | desc = ctx.description().splitlines()[0] | ||||
| oldnode, olddiff, drevid = oldmap.get(ctx.node(), (None, None, None)) | oldnode, olddiff, drevid = oldmap.get(ctx.node(), (None, None, None)) | ||||
| if drevid: | if drevid: | ||||
| drevdesc = ui.label(b'D%s' % drevid, b'phabricator.drev') | drevdesc = ui.label(b'D%s' % drevid, b'phabricator.drev') | ||||
| else: | else: | ||||