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

Pitgull bootstrap cli #264

Merged
merged 26 commits into from
Jun 12, 2021
Merged
Show file tree
Hide file tree
Changes from 6 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
56 changes: 0 additions & 56 deletions .github/workflows/native.yml

This file was deleted.

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"] }]
}
]
2 changes: 1 addition & 1 deletion bootstrap/src/main/scala/org/polyvariant/Args.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ object Args {
}


// TODO: Consider switching to https://ben.kirw.in/decline/
// 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())

Expand Down
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