Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Pitgull bootstrap cli #264

Merged
merged 26 commits into from
Jun 12, 2021
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8967c1c
getting started, issues with CE3 in Scala 3
majk-p May 31, 2021
a0992d9
fix build
majk-p May 31, 2021
628ec6f
add merge requests querry
majk-p May 31, 2021
ccc3b5d
logger
majk-p Jun 5, 2021
e906f5a
implement gitlab client
majk-p Jun 8, 2021
4be5d69
fix workflow
majk-p Jun 8, 2021
c7d209a
close qualified merge requests
majk-p Jun 8, 2021
a250e9c
cleanup
majk-p Jun 8, 2021
8627f8a
clean up build.sbt
majk-p Jun 8, 2021
9ff5c41
delete MR instead of closing it, implement webhook creation API
majk-p Jun 9, 2021
e73fb2f
exclude bootstrap from publishing artifact
majk-p Jun 9, 2021
b5afe33
cleanup
majk-p Jun 9, 2021
d1051a6
fix webhook creation
majk-p Jun 9, 2021
d929b29
build native image in github actions
majk-p Jun 9, 2021
b778495
use workflow from https://github.com/scalameta/sbt-native-image\#gene…
majk-p Jun 9, 2021
2ac8fd9
add better-tostring, fix reflection config in native-image
majk-p Jun 11, 2021
45a7e70
revert to using sbt workflow configuration instead of native.yml
majk-p Jun 11, 2021
6f3e26f
change fixme to link an issue
majk-p Jun 11, 2021
3f83775
wait for user consent before deleting merge requests
majk-p Jun 11, 2021
a6c3ded
extend note about blocked decline for argument parsing
majk-p Jun 11, 2021
66c1ad4
add usage info to both program and readme.md
majk-p Jun 11, 2021
3c2c6fe
Update README.md
majk-p Jun 12, 2021
a97d0c8
use cats-effect Console, configure scalafmt for scala 3, format Main
majk-p Jun 12, 2021
ae4c417
update reflect-config for native-image, apply formatting, some cleanup
majk-p Jun 12, 2021
45f6991
update readme - add reasoning behind MR deletion
majk-p Jun 12, 2021
2d5d4b1
scalafmt
majk-p Jun 12, 2021
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
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ jobs:

- run: sbt --client '++${{ matrix.scala }}; test; missinglinkCheck'

- name: Build native image
run: sbt bootstrap/nativeImage

- name: Upload binary
uses: actions/upload-artifact@v2
with:
name: pitgull-bootstrap-${{ matrix.os }}
path: ./bootstrap/target/native-image/bootstrap

- name: Compress target directories
run: tar cf targets.tar target gitlab/target core/target project/target

Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@
[![Powered by cats](https://img.shields.io/badge/powered%20by-cats-blue.svg)](https://github.com/typelevel/cats)
![Gluten free](https://img.shields.io/badge/gluten-free-orange.svg)

## Integrating with Pitgull

Along with Pitgull, we provide `pitgull-bootstrap` command line utility. This program prepares your gitlab project for integration with Pitgull by deleting existing Scala Steward mere requests and setting up a webhook for triggering Pitgull.
majk-p marked this conversation as resolved.
Show resolved Hide resolved

CLI Arguments:
--url - your gitlab url like https://gitlab.com/
--token - your gitlab personal token, needs to have full access to project
--project - project ID, can be found on project main page
--bot - user name of Scala Steward bot user
--webhook - Pitgull target url like https://pitgull.example.com/webhook

## Development

### Useful commands/links
Expand Down
226 changes: 226 additions & 0 deletions bootstrap/src/main/resources/reflect-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
[
{
"name":"byte[]"
majk-p marked this conversation as resolved.
Show resolved Hide resolved
},
{
majk-p marked this conversation as resolved.
Show resolved Hide resolved
"name":"cats.effect.unsafe.IORuntimeCompanionPlatform",
"fields":[{"name":"0bitmap$1", "allowUnsafeAccess":true}]
},
{
"name":"cats.effect.unsafe.WorkStealingThreadPool",
"fields":[{"name":"0bitmap$1", "allowUnsafeAccess":true}]
},
{
"name":"com.sun.crypto.provider.AESCipher$General",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"com.sun.crypto.provider.DHParameters",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"com.sun.crypto.provider.HmacCore$HmacSHA256",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"com.sun.crypto.provider.TlsMasterSecretGenerator",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"io.circe.Decoder$",
"fields":[{"name":"0bitmap$1", "allowUnsafeAccess":true}]
},
{
"name":"io.circe.Encoder$",
"fields":[{"name":"0bitmap$1", "allowUnsafeAccess":true}]
},
{
"name":"java.lang.String"
},
{
"name":"java.lang.String[]"
},
{
"name":"java.lang.invoke.VarHandle",
"methods":[{"name":"releaseFence","parameterTypes":[] }]
},
{
"name":"java.security.AlgorithmParametersSpi"
},
{
"name":"java.security.KeyStoreSpi"
},
{
"name":"java.security.MessageDigestSpi"
},
{
"name":"java.security.SecureRandomParameters"
},
{
"name":"java.security.interfaces.RSAPrivateKey"
},
{
"name":"java.security.interfaces.RSAPublicKey"
},
{
"name":"java.util.Date"
},
{
"name":"javax.security.auth.x500.X500Principal",
"fields":[{"name":"thisX500Name"}],
"methods":[{"name":"<init>","parameterTypes":["sun.security.x509.X500Name"] }]
},
{
"name":"sttp.model.Header$",
"fields":[{"name":"0bitmap$1", "allowUnsafeAccess":true}]
},
{
"name":"sun.misc.Unsafe",
"allDeclaredFields":true
},
{
"name":"sun.security.pkcs.SignerInfo[]"
},
{
"name":"sun.security.pkcs12.PKCS12KeyStore",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.pkcs12.PKCS12KeyStore$DualFormatPKCS12",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.provider.DSA$SHA224withDSA",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.provider.DSA$SHA256withDSA",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.provider.JavaKeyStore$DualFormatJKS",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.provider.JavaKeyStore$JKS",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.provider.NativePRNG",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.provider.SHA",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.provider.SHA2$SHA224",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.provider.SHA2$SHA256",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.provider.SHA5$SHA384",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.provider.SHA5$SHA512",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.provider.X509Factory",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.provider.certpath.PKIXCertPathValidator",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.rsa.RSAKeyFactory$Legacy",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.rsa.RSAPSSSignature",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.rsa.RSASignature$SHA224withRSA",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.rsa.RSASignature$SHA256withRSA",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.rsa.RSASignature$SHA384withRSA",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.ssl.KeyManagerFactoryImpl$SunX509",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.ssl.SSLContextImpl$DefaultSSLContext",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.ssl.TrustManagerFactoryImpl$PKIXFactory",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.util.ObjectIdentifier"
},
{
"name":"sun.security.x509.AuthorityInfoAccessExtension",
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
},
{
"name":"sun.security.x509.AuthorityKeyIdentifierExtension",
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
},
{
"name":"sun.security.x509.BasicConstraintsExtension",
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
},
{
"name":"sun.security.x509.CRLDistributionPointsExtension",
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
},
{
"name":"sun.security.x509.CertificateExtensions"
},
{
"name":"sun.security.x509.CertificatePoliciesExtension",
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
},
{
"name":"sun.security.x509.ExtendedKeyUsageExtension",
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
},
{
"name":"sun.security.x509.IssuerAlternativeNameExtension",
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
},
{
"name":"sun.security.x509.KeyUsageExtension",
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
},
{
"name":"sun.security.x509.NetscapeCertTypeExtension",
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
},
{
"name":"sun.security.x509.PrivateKeyUsageExtension",
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
},
{
"name":"sun.security.x509.SubjectAlternativeNameExtension",
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
},
{
"name":"sun.security.x509.SubjectKeyIdentifierExtension",
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
}
]
21 changes: 21 additions & 0 deletions bootstrap/src/main/scala/org/polyvariant/Args.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.polyvariant

object Args {
private val switch = "-(\\w+)".r
private val option = "--(\\w+)".r

private def parseNext(pendingArguments: List[String], previousResult: Map[String, String]): Map[String, String] =
pendingArguments match {
case Nil => previousResult
case option(opt) :: value :: tail => parseNext(tail, previousResult ++ Map(opt -> value))
case switch(opt) :: tail => parseNext(tail, previousResult ++ Map(opt -> null))
case text :: Nil => previousResult ++ Map(text -> null)
case text :: tail => parseNext(tail, previousResult ++ Map(text -> null))
}


// TODO: Consider switching to https://ben.kirw.in/decline/ after https://github.com/bkirwi/decline/pull/293
def parse(args: List[String]): Map[String, String] =
parseNext(args.toList, Map())

}
43 changes: 43 additions & 0 deletions bootstrap/src/main/scala/org/polyvariant/Config.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.polyvariant

import cats.implicits.*
import cats.MonadThrow
import sttp.model.Uri
import scala.util.Try

final case class Config(
gitlabUri: Uri,
token: String,
project: Long,
botUser: String,
pitgullWebhookUrl: Uri
)
object Config {
def fromArgs[F[_]: MonadThrow](args: Map[String, String]): F[Config] =
MonadThrow[F].fromTry {
majk-p marked this conversation as resolved.
Show resolved Hide resolved
Try {
Config(
Uri.unsafeParse(args("url")),
args("token"),
args("project").toLong,
args("bot"),
Uri.unsafeParse(args("webhook"))
)
}.recoverWith {
case _ => Try{throw ArgumentsParsingException}
}
}
val usage = """
|This program prepares your gitlab project for integration with Pitgull
|by deleting existing Scala Steward mere requests and setting up
|a webhook for triggering Pitgull.
|
|CLI Arguments:
| --url - your gitlab url like https://gitlab.com/
| --token - your gitlab personal token, needs to have full access to project
| --project - project ID, can be found on project main page
| --bot - user name of Scala Steward bot user
| --webhook - Pitgull target url like https://pitgull.example.com/webhook
""".stripMargin
case object ArgumentsParsingException extends Exception("Failed to parse CLI arguments")
}
majk-p marked this conversation as resolved.
Show resolved Hide resolved
17 changes: 17 additions & 0 deletions bootstrap/src/main/scala/org/polyvariant/Console.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.polyvariant

import cats.effect.kernel.Sync
import scala.io.StdIn.{readChar => unsafeReadChar}

trait Console[F[_]] {
def readChar(): F[Char]
majk-p marked this conversation as resolved.
Show resolved Hide resolved
}

object Console {
def apply[F[_]](using ev: Console[F]): Console[F] = ev

def instance[F[_]: Sync] = new Console[F] {
def readChar(): F[Char] =
Sync[F].delay(unsafeReadChar)
}
}
Loading