181 else: |
181 else: |
182 process(k, v) |
182 process(k, v) |
183 process(b'', params) |
183 process(b'', params) |
184 return util.urlreq.urlencode(flatparams) |
184 return util.urlreq.urlencode(flatparams) |
185 |
185 |
186 def readurltoken(repo): |
186 def readurltoken(ui): |
187 """return conduit url, token and make sure they exist |
187 """return conduit url, token and make sure they exist |
188 |
188 |
189 Currently read from [auth] config section. In the future, it might |
189 Currently read from [auth] config section. In the future, it might |
190 make sense to read from .arcconfig and .arcrc as well. |
190 make sense to read from .arcconfig and .arcrc as well. |
191 """ |
191 """ |
192 url = repo.ui.config(b'phabricator', b'url') |
192 url = ui.config(b'phabricator', b'url') |
193 if not url: |
193 if not url: |
194 raise error.Abort(_(b'config %s.%s is required') |
194 raise error.Abort(_(b'config %s.%s is required') |
195 % (b'phabricator', b'url')) |
195 % (b'phabricator', b'url')) |
196 |
196 |
197 res = httpconnectionmod.readauthforuri(repo.ui, url, util.url(url).user) |
197 res = httpconnectionmod.readauthforuri(ui, url, util.url(url).user) |
198 token = None |
198 token = None |
199 |
199 |
200 if res: |
200 if res: |
201 group, auth = res |
201 group, auth = res |
202 |
202 |
203 repo.ui.debug(b"using auth.%s.* for authentication\n" % group) |
203 ui.debug(b"using auth.%s.* for authentication\n" % group) |
204 |
204 |
205 token = auth.get(b'phabtoken') |
205 token = auth.get(b'phabtoken') |
206 |
206 |
207 if not token: |
207 if not token: |
208 raise error.Abort(_(b'Can\'t find conduit token associated to %s') |
208 raise error.Abort(_(b'Can\'t find conduit token associated to %s') |
210 |
210 |
211 return url, token |
211 return url, token |
212 |
212 |
213 def callconduit(repo, name, params): |
213 def callconduit(repo, name, params): |
214 """call Conduit API, params is a dict. return json.loads result, or None""" |
214 """call Conduit API, params is a dict. return json.loads result, or None""" |
215 host, token = readurltoken(repo) |
215 host, token = readurltoken(repo.ui) |
216 url, authinfo = util.url(b'/'.join([host, b'api', name])).authinfo() |
216 url, authinfo = util.url(b'/'.join([host, b'api', name])).authinfo() |
217 repo.ui.debug(b'Conduit Call: %s %s\n' % (url, pycompat.byterepr(params))) |
217 repo.ui.debug(b'Conduit Call: %s %s\n' % (url, pycompat.byterepr(params))) |
218 params = params.copy() |
218 params = params.copy() |
219 params[b'api.token'] = token |
219 params[b'api.token'] = token |
220 data = urlencodenested(params) |
220 data = urlencodenested(params) |
651 _metanamemap = util.sortdict([(b'user', b'User'), (b'date', b'Date'), |
651 _metanamemap = util.sortdict([(b'user', b'User'), (b'date', b'Date'), |
652 (b'branch', b'Branch'), (b'node', b'Node ID'), |
652 (b'branch', b'Branch'), (b'node', b'Node ID'), |
653 (b'parent', b'Parent ')]) |
653 (b'parent', b'Parent ')]) |
654 |
654 |
655 def _confirmbeforesend(repo, revs, oldmap): |
655 def _confirmbeforesend(repo, revs, oldmap): |
656 url, token = readurltoken(repo) |
656 url, token = readurltoken(repo.ui) |
657 ui = repo.ui |
657 ui = repo.ui |
658 for rev in revs: |
658 for rev in revs: |
659 ctx = repo[rev] |
659 ctx = repo[rev] |
660 desc = ctx.description().splitlines()[0] |
660 desc = ctx.description().splitlines()[0] |
661 oldnode, olddiff, drevid = oldmap.get(ctx.node(), (None, None, None)) |
661 oldnode, olddiff, drevid = oldmap.get(ctx.node(), (None, None, None)) |