-
Notifications
You must be signed in to change notification settings - Fork 40
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
Gitlab integration #44
base: master
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## master #44 +/- ##
==========================================
+ Coverage 58.52% 60.08% +1.56%
==========================================
Files 134 130 -4
Lines 4330 4224 -106
Branches 107 121 +14
==========================================
+ Hits 2534 2538 +4
+ Misses 1796 1686 -110
Continue to review full report at Codecov.
|
d0b2131
to
9f41949
Compare
9f41949
to
1fd71a9
Compare
cb5273d
to
3060b3b
Compare
@juanjovazquez what's the status of this PR? I would like to label it with a status for admin purposes :-) |
@timperrett It's almost all covered except My goal so far has been not to be very disruptive with respect to the current code in order to have a first version working as soon as possible. Later, algebra and interpreters could be refactored to better accommodate the three most important scms: Github, Gitlab and Bitbucket. If you prefer, we could merge after rebasing as it is now in order to tackle what is missing in individual issues. This PR starts to be too big. Please, let me know what works better for you. |
@timperrett webhooks client api implemented. However, I bumped into another drawback: Gitlab's hooks won't set the |
@timperrett Definitely stuck with the So, my plan is to modify the Quite hacky, but to be honest, I can't find a better way to accommodate this requirement without tackling a profound refactoring. So, if you agree, I'll implement it this way, at least in a first version. |
@juanjovazquez is there the ability to attach files to a release / tag in GitLab? That's going to be really important so hope it is available (otherwise this might be moot). @adelbertc @kaiserpelagic can you just chime in with anything you can think of that might cause a problem with releases having a string ID? Provided they never collide then it should be fine. The only drawback might be table indexing, but I dont recall off the top of my head which columns are indexed; im thinking its not a huge problem. |
@timperrett It's a bit hacky but yes, Gitlab does offer the capability of attaching files to tags as release notes through the web interface. It is hacky because Gitlab just uploads the file generating an {
"commit": {
"id": "2695effb5807a22ff3d138d593fd856244e155e7",
"short_id": "2695effb",
"title": "Initial commit",
"created_at": "2017-07-26T11:08:53.000+02:00",
"parent_ids": [
"2a4b78934375d7f53875269ffd4f45fd83a84ebe"
],
"message": "Initial commit",
"author_name": "John Smith",
"author_email": "[email protected]",
"authored_date": "2012-05-28T04:42:42-07:00",
"committer_name": "Jack Smith",
"committer_email": "[email protected]",
"committed_date": "2012-05-28T04:42:42-07:00"
},
"release": {
"tag_name": "1.0.0",
"description": "[foo.json](/uploads/<guid>/foo.json)"
},
"name": "v1.0.0",
"message": null
} When there's no release, the As for the Anyway, I'd still need to change the |
@@ -116,7 +116,7 @@ ALTER TABLE PUBLIC."deployments" ADD CONSTRAINT PUBLIC.CONSTRAINT_F PRIMARY KEY( | |||
CREATE INDEX PUBLIC."deployments_guid_idx" ON PUBLIC."deployments"("guid"); | |||
CREATE CACHED TABLE PUBLIC."audit_log"( | |||
"id" BIGINT DEFAULT (NEXT VALUE FOR PUBLIC.SYSTEM_SEQUENCE_15FD08D0_DDC1_4ECB_8FB3_38AB48CE23B4) NOT NULL NULL_TO_DEFAULT SEQUENCE PUBLIC.SYSTEM_SEQUENCE_15FD08D0_DDC1_4ECB_8FB3_38AB48CE23B4, | |||
"release_id" BIGINT, | |||
"release_id" VARCHAR(25), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICS this is the only change affecting de data model so far as release_id
was already defined as VARCHAR(25)
in the releases
table
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@juanjovazquez we should never be changing an existing migration. If you want to change a DB scheme you should create a new migration. Flyaway uses a numbering convention in the name, so you'd create a filed called V2_1__alter_relase_id.sql where you alter the "audit_log" table.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kaiserpelagic Got it. I'll change it right away.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@juanjovazquez it seems like we also need a migration for the releases
table.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kaiserpelagic Why is that?. release_id
was already a VARCHAR(25)
in the releases
table.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@juanjovazquez interesting, I did not realize that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kaiserpelagic yep, I got surprise too ;-)
@@ -17,5 +17,6 @@ | |||
package nelson | |||
|
|||
final case class AccessToken( | |||
value: String | |||
value: String, | |||
isPrivate: Boolean = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because Gitlab treats OAuth and private personal tokens differently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a sum type instead?
sealed abstract class Token extends Product with Serializable
object Token {
final case class PersonalToken(...) extends Token
final case class OAuth(...) extends Token
}
organizationBlacklist = cfg.lookup[List[String]]("organization-blacklist").getOrElse(Nil), | ||
organizationAdminList = cfg.lookup[List[String]]("organization-admins").getOrElse(Nil) | ||
private def readGithub(cfg: KConfig): ScmConfig = { | ||
val service = cfg.lookup[String]("service").getOrElse("github") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The service configuration param is used to choose the scm interpreter: Gitlab or GIthub (default).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reading configuration for different interpreters I might do something like
kfg.lookup[String]("scm") match {
case Some("github") => readGithub(kfg.subconfig("github"))
case Some("gitlab") => readGitlab(kfg.subconfig("gitlab"))
case _ => None
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the time being it's the same configuration.
@timperrett I've updated the PR modifying the |
@@ -395,7 +471,12 @@ object Config { | |||
val nomadcfg = readNomad(cfg.subconfig("nelson.nomad")) | |||
|
|||
val gitcfg = readGithub(cfg.subconfig("nelson.github")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is configuration of github and gitlab under nelson.github
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, for the time being. Which one is used is determined by the param service
, e.g.
service = "gitlab"
Default is github
anyway.
I tried not to add many breaking changes in this first version of Gitlab support, but I think that we should re-think the algebra and the configuration to be more generic. Probably in another PR if you agree.
@@ -395,7 +471,12 @@ object Config { | |||
val nomadcfg = readNomad(cfg.subconfig("nelson.nomad")) | |||
|
|||
val gitcfg = readGithub(cfg.subconfig("nelson.github")) | |||
val git = new Github.GithubHttp(gitcfg, http0) | |||
val git: GithubOp ~> Task = gitcfg match { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use something other than GithubOp
now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same idea as before. I left that kind of changes for a second review.
core/src/main/scala/Gitlab.scala
Outdated
|
||
case GetUserRepositories(t: AccessToken) => | ||
def go(uri: String)(accum: List[Repo]): List[Repo] = { | ||
val EntityWithMeta(repos, pagination) = authFetchWithMeta[List[Repo]](uri, t).run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should never be calling .run
in code like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, it's basically the same thing as in the Github interpreter. I'll have it a look anyway.
4ce3c4b
to
e25dd68
Compare
core/src/main/scala/Json.scala
Outdated
@@ -505,12 +509,22 @@ object Json { | |||
e <- (z --\ "repository" --\ "id").as[Long] | |||
} yield { | |||
Github.ReleaseEvent( | |||
id = a, | |||
id = a.toString, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not decode it as a String
above, instead of calling toString
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, take it for granted.
@@ -30,7 +30,7 @@ final case class Released( | |||
/* when was this release created */ | |||
timestamp: Instant, | |||
/* reference id from github */ | |||
releaseId: Long, | |||
releaseId: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this a String
now? does Gitlab not represent it was a number?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, it's not the case. Gitlab has no releases
, just tags
, and these have no numeric ids
either. 😞
ab9f2e9
to
61158e6
Compare
61158e6
to
ff26ba4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you want to merge this as is or just put it up for review? I think it'd also be good to get changes that others suggested in, like renaming GithubOp
to something more generic, etc.
Perhaps those can be made in a separate commit so it's easy to revert if you're concerned about touching too many things.
--: limitations under the License. | ||
--: | ||
--: ---------------------------------------------------------------------------- | ||
ALTER TABLE PUBLIC."audit_log" ALTER COLUMN "release_id" VARCHAR(25); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not familiar with DB migrations, this will probably need @timperrett 's eyes.
@@ -17,5 +17,6 @@ | |||
package nelson | |||
|
|||
final case class AccessToken( | |||
value: String | |||
value: String, | |||
isPrivate: Boolean = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a sum type instead?
sealed abstract class Token extends Product with Serializable
object Token {
final case class PersonalToken(...) extends Token
final case class OAuth(...) extends Token
}
case _: ScmConfig.GithubConfig => | ||
new Github.GithubHttp(gitcfg, http0) | ||
case _ => | ||
new Gitlab.GitlabHttp(gitcfg, http4sClient(timeout)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Picky but I generally prefer pat mat instead of type casing, if only for theoretical reasons described here: https://typelevel.org/blog/2014/11/10/why_is_adt_pattern_matching_allowed.html
Also perhaps get rid of _
and do an explicit match on GitLab
's constructor so any potential future additions error here as they should.
@@ -226,7 +226,7 @@ object Github { | |||
} | |||
} | |||
|
|||
final class GithubHttp(cfg: GithubConfig, http: dispatch.Http) extends (GithubOp ~> Task) { | |||
final class GithubHttp(cfg: ScmConfig, http: dispatch.Http) extends (GithubOp ~> Task) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mmmmm this is a bit bothersome. On one hand I don't like using subtypes for data types that are ADTs on the other hand the only config this should be called with is the GithubConfig
.. I would learn towards using the subtype anyways.
@@ -76,13 +76,13 @@ object Github { | |||
) extends Event | |||
|
|||
final case class ReleaseEvent( | |||
id: Long, | |||
id: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One trick we can try is parameterize it into ReleaseEvent[A]
so we have ReleaseEvent[Long]
and ReleaseEvent[String]
.. wdyt? @timperrett @kaiserpelagic
DecodeJson(c => (c --\ "access_token").as[String]).map(AccessToken.apply(_)) | ||
|
||
implicit lazy val AccessTokenEncoder: EncodeJson[AccessToken] = | ||
jencode1L((t: AccessToken) => t.value)("access_token") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change?
closes #43