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

Adds back access token to GitHub #118

Merged
merged 1 commit into from
Feb 24, 2025
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
3 changes: 2 additions & 1 deletion app/controllers/HomeController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class HomeController @Inject()(
cache: SyncCacheApi
) extends AbstractController(cc) {

private val accessToken = configuration.get[String]("accessToken")
private val organization = configuration.get[String]("githubOrganisation")
private val repository = configuration.get[String]("githubRepository")
private val branch = configuration.get[String]("githubBranch")
Expand Down Expand Up @@ -122,7 +123,7 @@ class HomeController @Inject()(
} else {
cache.get(post.authorName) match {
case None =>
val getUser = Github().users.get(post.authorName).execFuture[HttpResponse[String]]()
val getUser = Github(Option(accessToken)).users.get(post.authorName).execFuture[HttpResponse[String]]()
getUser.map {
case Left(_) => Ok(views.html.post(post))
case Right(re) =>
Expand Down
5 changes: 3 additions & 2 deletions app/modules/ApplicationStart.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ class ApplicationStart @Inject()(
cache: SyncCacheApi
) {

private val accessToken = configuration.get[String]("accessToken")
private val organization = configuration.get[String]("githubOrganisation")
private val repository = configuration.get[String]("githubRepository")
private val branch = configuration.get[String]("githubBranch")

private def getContents = Github().repos.getContents(organization, repository, "posts", Option(branch)).execFuture[HttpResponse[String]]()
private def getContents = Github(Option(accessToken)).repos.getContents(organization, repository, "posts", Option(branch)).execFuture[HttpResponse[String]]()

{
// Parse all and put into cache
Expand Down Expand Up @@ -107,7 +108,7 @@ class ApplicationStart @Inject()(
val authorName = post.authorName
cache.get(authorName) match {
case None =>
val getUser = Github().users.get(authorName).execFuture[HttpResponse[String]]()
val getUser = Github(Option(accessToken)).users.get(authorName).execFuture[HttpResponse[String]]()
val postWithAuthor = getUser.map {
case Left(_) => p
case Right(rUser) =>
Expand Down
1 change: 1 addition & 0 deletions conf/application.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# https://www.playframework.com/documentation/latest/Configuration

# Github configuration
accessToken = ${?access_token}
githubOrganisation = lunatech-labs
githubOrganisation = ${?github_organisation}
githubRepository = lunatech-blog
Expand Down