Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not show bio if it is null #33

Merged
merged 1 commit into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions function/data/linuxsuren-bot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"login": "linuxsuren-bot",
"id": 39147110,
"node_id": "MDQ6VXNlcjM5MTQ3MTEw",
"avatar_url": "https://avatars.githubusercontent.com/u/39147110?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/linuxsuren-bot",
"html_url": "https://github.com/linuxsuren-bot",
"followers_url": "https://api.github.com/users/linuxsuren-bot/followers",
"following_url": "https://api.github.com/users/linuxsuren-bot/following{/other_user}",
"gists_url": "https://api.github.com/users/linuxsuren-bot/gists{/gist_id}",
"starred_url": "https://api.github.com/users/linuxsuren-bot/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/linuxsuren-bot/subscriptions",
"organizations_url": "https://api.github.com/users/linuxsuren-bot/orgs",
"repos_url": "https://api.github.com/users/linuxsuren-bot/repos",
"events_url": "https://api.github.com/users/linuxsuren-bot/events{/privacy}",
"received_events_url": "https://api.github.com/users/linuxsuren-bot/received_events",
"type": "User",
"site_admin": false,
"name": "LinuxSuRen-bot",
"company": null,
"blog": "",
"location": null,
"email": null,
"hireable": null,
"bio": null,
"twitter_username": null,
"public_repos": 35,
"public_gists": 0,
"followers": 1,
"following": 2,
"created_at": "2018-05-10T04:38:59Z",
"updated_at": "2022-06-15T02:15:00Z"
}
4 changes: 2 additions & 2 deletions function/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ func GithubUserLink(id string, bio bool) (link string) {
)
if data, err = ghRequestAsMap(api); err == nil {
link = fmt.Sprintf("[%s](%s)", data["name"], data["html_url"])
if bio {
link = fmt.Sprintf("%s (%s)", link, data["bio"])
if bioText, ok := data["bio"]; ok && bio && bioText != nil {
link = fmt.Sprintf("%s (%s)", link, bioText)
}
}
return
Expand Down
32 changes: 23 additions & 9 deletions function/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,49 +53,63 @@ func TestGithubUserLink(t *testing.T) {
bio bool
}
tests := []struct {
name string
args args
want string
name string
mockUser string
args args
want string
}{{
name: "normal case without bio",
name: "normal case without bio",
mockUser: "linuxsuren",
args: args{
id: "linuxsuren",
bio: false,
},
want: `[Rick](https://github.com/LinuxSuRen)`,
}, {
name: "normal case with bio",
name: "normal case with bio",
mockUser: "linuxsuren",
args: args{
id: "linuxsuren",
bio: true,
},
want: `[Rick](https://github.com/LinuxSuRen) (程序员,业余开源布道者)`,
}, {
name: "with whitespace",
name: "with whitespace",
mockUser: "linuxsuren",
args: args{
id: "this is not id",
bio: false,
},
want: "this is not id",
}, {
name: "has Markdown style link",
name: "has Markdown style link",
mockUser: "linuxsuren",
args: args{
id: "[name](link)",
bio: false,
},
want: "[name](link)",
}, {
name: "has Markdown style link, want bio",
name: "has Markdown style link, want bio",
mockUser: "linuxsuren",
args: args{
id: "[Rick](https://github.com/linuxsuren)",
bio: true,
},
want: `[Rick](https://github.com/LinuxSuRen) (程序员,业余开源布道者)`,
}, {
name: "do not have bio",
mockUser: "linuxsuren-bot",
args: args{
id: "linuxsuren-bot",
bio: true,
},
want: `[LinuxSuRen-bot](https://github.com/linuxsuren-bot)`,
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
defer gock.Off()
mockGitHubUser("linuxsuren")
mockGitHubUser(tt.mockUser)
assert.Equalf(t, tt.want, GithubUserLink(tt.args.id, tt.args.bio), "GithubUserLink(%v, %v)", tt.args.id, tt.args.bio)
})
}
Expand Down