Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F77300
github.ex
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
github.ex
View Options
defmodule
Nola.Plugins.Link.Github
do
@behaviour
Nola.Plugins.Link
@impl
true
def
match
(
uri
=
%
URI
{
host
:
"github.com"
,
path
:
path
},
_
)
do
case
String
.
split
(
path
,
"/"
)
do
[
""
,
user
,
repo
]
->
{
true
,
%{
user
:
user
,
repo
:
repo
,
path
:
"
#{
user
}
/
#{
repo
}
"
}}
_
->
false
end
end
def
match
(
_
,
_
),
do
:
false
@impl
true
def
post_match
(
_
,
_
,
_
,
_
),
do
:
false
@impl
true
def
expand
(
_uri
,
%{
user
:
user
,
repo
:
repo
},
_opts
)
do
case
HTTPoison
.
get
(
"https://api.github.com/repos/
#{
user
}
/
#{
repo
}
"
)
do
{
:ok
,
%
HTTPoison.Response
{
status_code
:
200
,
body
:
body
}}
->
{
:ok
,
json
}
=
Jason
.
decode
(
body
)
src
=
json
[
"source"
][
"full_name"
]
disabled
=
if
(
json
[
"disabled"
],
do
:
" (disabled)"
,
else
:
""
)
archived
=
if
(
json
[
"archived"
],
do
:
" (archived)"
,
else
:
""
)
fork
=
if
src
&&
src
!=
json
[
"full_name"
]
do
" (⑂
#{
json
[
"source"
][
"full_name"
]
}
)"
else
""
end
start
=
"
#{
json
[
"full_name"
]
}#{
disabled
}#{
archived
}#{
fork
}
-
#{
json
[
"description"
]
}
"
tags
=
for
(
t
<-
json
[
"topics"
]
||
[],
do
:
"
#
#{
t
}
"
)
|>
Enum
.
intersperse
(
", "
)
|>
Enum
.
join
(
""
)
lang
=
if
(
json
[
"language"
],
do
:
"
#{
json
[
"language"
]
}
- "
,
else
:
""
)
issues
=
if
(
json
[
"open_issues_count"
],
do
:
"
#{
json
[
"open_issues_count"
]
}
issues - "
,
else
:
""
)
last_push
=
if
at
=
json
[
"pushed_at"
]
do
{
:ok
,
date
,
_
}
=
DateTime
.
from_iso8601
(
at
)
" - last pushed
#{
DateTime
.
to_string
(
date
)
}
"
else
""
end
network
=
"
#{
lang
}#{
issues
}#{
json
[
"stargazers_count"
]
}
stars -
#{
json
[
"subscribers_count"
]
}
watchers -
#{
json
[
"forks_count"
]
}
forks
#{
last_push
}
"
{
:ok
,
[
start
,
tags
,
network
]}
other
->
:error
end
end
end
File Metadata
Details
Attached
Mime Type
text/x-ruby
Expires
Sun, Jul 6, 2:57 PM (18 h, 52 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
49830
Default Alt Text
github.ex (1 KB)
Attached To
rNOLA Nola
Event Timeline
Log In to Comment