Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
hub
提交
878f1967
H
hub
项目概览
github
/
hub
9 个月 前同步成功
通知
3
Star
22523
Fork
2406
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hub
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
878f1967
编写于
7月 19, 2019
作者:
M
Mislav Marohnić
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2198 from github/actions-auth
Allow hub used in Actions by specifying GITHUB_USER
上级
64771fb5
2aef0031
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
66 addition
and
8 deletion
+66
-8
features/authentication.feature
features/authentication.feature
+48
-0
github/client.go
github/client.go
+8
-4
github/config.go
github/config.go
+10
-4
未找到文件。
features/authentication.feature
浏览文件 @
878f1967
...
...
@@ -241,6 +241,54 @@ Feature: OAuth authentication
And
the output should not contain
"github.com username"
And
the file
"../home/.config/hub"
should not exist
Scenario
:
Credentials from GITHUB_TOKEN when obtaining username fails
Given I am in "git
:
//github.com/monalisa/playground.git"
git
repo
Given the GitHub API server
:
"""
get('/user') {
status 403
json :message => "Resource not accessible by integration",
:documentation_url => "https://developer.github.com/v3/users/#get-the-authenticated-user"
}
"""
Given
$GITHUB_TOKEN is
"OTOKEN"
Given
$GITHUB_USER is
""
When
I run `hub release show v1.2.0`
Then
the output should not contain
"github.com password"
And
the output should not contain
"github.com username"
And
the file
"../home/.config/hub"
should not exist
And
the exit status should be 1
And the stderr should contain exactly
:
"""
Error getting current user: Forbidden (HTTP 403)
Resource not accessible by integration
You must specify GITHUB_USER via environment variable.\n
"""
Scenario
:
Credentials from GITHUB_TOKEN and GITHUB_USER
Given I am in "git
:
//github.com/monalisa/playground.git"
git
repo
Given the GitHub API server
:
"""
get('/user') {
status 403
json :message => "Resource not accessible by integration",
:documentation_url => "https://developer.github.com/v3/users/#get-the-authenticated-user"
}
get('/repos/monalisa/playground/releases') {
halt 401 unless request.env["HTTP_AUTHORIZATION"] == "token OTOKEN"
json [
{ tag_name: 'v1.2.0',
}
]
}
"""
Given
$GITHUB_TOKEN is
"OTOKEN"
Given
$GITHUB_USER is
"hubot"
When
I successfully run `hub release show v1.2.0`
Then
the output should not contain
"github.com password"
And
the output should not contain
"github.com username"
And
the file
"../home/.config/hub"
should not exist
Scenario
:
Credentials from GITHUB_TOKEN override those from config file
Given
I am
"mislav"
on github.com with OAuth token
"OTOKEN"
Given the GitHub API server
:
...
...
github/client.go
浏览文件 @
878f1967
...
...
@@ -921,14 +921,15 @@ func (client *Client) FindOrCreateToken(user, password, twoFactorCode string) (t
return
}
func
(
client
*
Client
)
ensureAccessToken
()
(
err
error
)
{
func
(
client
*
Client
)
ensureAccessToken
()
error
{
if
client
.
Host
.
AccessToken
==
""
{
host
,
err
:=
CurrentConfig
()
.
PromptForHost
(
client
.
Host
.
Host
)
if
err
=
=
nil
{
client
.
Host
=
host
if
err
!
=
nil
{
return
err
}
client
.
Host
=
host
}
return
return
nil
}
func
(
client
*
Client
)
simpleApi
()
(
c
*
simpleClient
,
err
error
)
{
...
...
@@ -1043,6 +1044,9 @@ func FormatError(action string, err error) (ee error) {
errorMessage
=
strings
.
Join
(
errorSentences
,
"
\n
"
)
}
else
{
errorMessage
=
e
.
Message
if
action
==
"getting current user"
&&
e
.
Message
==
"Resource not accessible by integration"
{
errorMessage
=
errorMessage
+
"
\n
You must specify GITHUB_USER via environment variable."
}
}
if
errorMessage
!=
""
{
...
...
github/config.go
浏览文件 @
878f1967
...
...
@@ -87,11 +87,17 @@ func (c *Config) PromptForHost(host string) (h *Host, err error) {
}
}
currentUser
,
err
:=
client
.
CurrentUser
()
if
err
!=
nil
{
return
userFromEnv
:=
os
.
Getenv
(
"GITHUB_USER"
)
if
tokenFromEnv
&&
userFromEnv
!=
""
{
h
.
User
=
userFromEnv
}
else
{
var
currentUser
*
User
currentUser
,
err
=
client
.
CurrentUser
()
if
err
!=
nil
{
return
}
h
.
User
=
currentUser
.
Login
}
h
.
User
=
currentUser
.
Login
if
!
tokenFromEnv
{
err
=
newConfigService
()
.
Save
(
configsFile
(),
c
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录