Skip to content
Open
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ adhere to https://github.com/olivierlacan/keep-a-changelog.
### Internal
- [Issue-#31] Reformat code according to Kotlin coding conventions
- [Issue-#33] Move all GitHub API calls to GitHubAPIClient to adhere to the Single Responsibility Principle
- [Issue-#40] Migrate Klaxon to kotlinx.serialization JSON Serializer library

## [1.3.0] - 2021-02-01

### Added
- [Issue-#14] Github authentication token configurable through app.properties
- [Issue-#14] GitHub's authentication token configurable through app.properties
- [Issue-#29] Improve app user experience by using `Clikt` library for command line user interaction

### Changed
Expand Down Expand Up @@ -85,3 +86,4 @@ adhere to https://github.com/olivierlacan/keep-a-changelog.
[Issue-#33]: https://github.com/ClausPolanka/github-pr-factory/issues/33
[Issue-#35]: https://github.com/ClausPolanka/github-pr-factory/issues/35
[Issue-#36]: https://github.com/ClausPolanka/github-pr-factory/issues/36
[Issue-#40]: https://github.com/ClausPolanka/github-pr-factory/issues/40
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## github-pr-factory
George Hiring Github Pull Request Factory
George Hiring GitHub Pull Request Factory

The **github-pr-factory** allows creating pull requests via command line.
The candidate has to create git branches with the following naming scheme:
Expand Down Expand Up @@ -83,10 +83,10 @@ Options:

### user.properties - Setting user properties to reduce typing

You can set your Github authentication token in a file called `user.properties`.
You can set your GitHub authentication token in a file called `user.properties`.
The `github-pr-factory` app expects the file to be either on the classpath or in
the same directory in which the app gets executed.
In case you are using a `user.properties` you can set the Github authentication
In case you are using a `user.properties` you can set the GitHub authentication
token by adding a key-value-pair `github-token=TODO` to the file where the `TODO`
must be replaced with your token. Therefore, you don't need to pass the token
neither to the `open` nor `close` command.
Expand Down
34 changes: 25 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>github-pr-factory</groupId>
Expand All @@ -15,7 +16,7 @@
<assertj.version>3.19.0</assertj.version>
<wiremock.version>2.28.0</wiremock.version>
<khttp.version>1.0.0</khttp.version>
<klaxon.version>5.5</klaxon.version>
<kotlinx.serialization.version>1.2.1</kotlinx.serialization.version>
<maven-surefire-plugin.version>3.0.0-M4</maven-surefire-plugin.version>
<maven-jar-plugin.version>3.2.0</maven-jar-plugin.version>
<maven-assembly-plugin.version>3.3.0</maven-assembly-plugin.version>
Expand All @@ -33,17 +34,16 @@
<artifactId>kotlin-reflect</artifactId>
<version>${kotlin.version}</version>
</dependency>
<!-- Kotlin JSON parser -->
<dependency>
<groupId>com.beust</groupId>
<artifactId>klaxon</artifactId>
<version>${klaxon.version}</version>
</dependency>
<dependency>
<groupId>khttp</groupId>
<artifactId>khttp</artifactId>
<version>${khttp.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-serialization-json</artifactId>
<version>${kotlinx.serialization.version}</version>
</dependency>
<dependency>
<groupId>com.github.ajalt.clikt</groupId>
<artifactId>clikt-jvm</artifactId>
Expand Down Expand Up @@ -84,6 +84,12 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<includes>
<include>**/*IT</include>
<include>**/*Test</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
Expand All @@ -104,8 +110,18 @@
</execution>
</executions>
<configuration>
<compilerPlugins>
<plugin>kotlinx-serialization</plugin>
</compilerPlugins>
<jvmTarget>1.8</jvmTarget>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-serialization</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -150,7 +166,7 @@
</build>

<repositories>
<!-- Klaxon, khttp dependencies are located in jcenter maven repository -->
<!-- khttp dependencies are located in jcenter maven repository -->
<repository>
<id>jcenter</id>
<url>https://jcenter.bintray.com/</url>
Expand Down
13 changes: 12 additions & 1 deletion src/main/kotlin/pullrequestfactory/Main.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
package pullrequestfactory

import com.github.ajalt.clikt.core.subcommands
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.json.Json
import kotlinx.serialization.modules.SerializersModule
import kotlinx.serialization.modules.contextual
import pullrequestfactory.io.clikt.CloseCommand
import pullrequestfactory.io.clikt.CommandArgs
import pullrequestfactory.io.clikt.GitHubPrFactoryCommand
import pullrequestfactory.io.clikt.OpenCommand
import pullrequestfactory.io.programs.impl.FileAppProperties
import pullrequestfactory.io.programs.impl.InstantSerializer
import pullrequestfactory.io.uis.ConsoleUI

@ExperimentalSerializationApi
fun main(args: Array<String>) {
val appProps = FileAppProperties("app.properties")
val cmdArgs = CommandArgs(
appProps.getGithubBaseUrl(),
appProps.getGithubRepositoryPath(),
"user.properties",
ConsoleUI()
ConsoleUI(),
jsonSerializer()
)
GitHubPrFactoryCommand(appProps.getProjectVersion())
.subcommands(OpenCommand(cmdArgs), CloseCommand(cmdArgs))
.main(args)
}

@ExperimentalSerializationApi
fun jsonSerializer() =
Json { ignoreUnknownKeys = true; serializersModule = SerializersModule { contextual(InstantSerializer) } }
6 changes: 3 additions & 3 deletions src/main/kotlin/pullrequestfactory/domain/PairingPartner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ enum class PairingPartner(vararg val pullRequestNames: String) {
MARTON("Marton"),
;

fun contains(branchName: String): Boolean = pullRequestNames.contains(branchName.capitalize())
fun contains(branchName: String): Boolean = pullRequestNames.contains(branchName.replaceFirstChar { it.titlecase() })

fun pullRequestName() = name.toLowerCase().capitalize()
fun pullRequestName() = name.lowercase().replaceFirstChar { it.titlecase() }

companion object {

fun from(value: String) =
values().find { it.pullRequestNames.contains(value.capitalize()) }
values().find { it.pullRequestNames.contains(value.replaceFirstChar { c -> c.titlecase() }) }

fun from(ordinal: Int) = try {
val pp = values()[ordinal]
Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/pullrequestfactory/domain/branches/Branch.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package pullrequestfactory.domain.branches

import kotlinx.serialization.Serializable

@Serializable
data class Branch(val name: String) {

fun iterationNr(): Int = parts().dropLast(1).last().toInt()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class Branches(
val prs = branches.mapIndexed { idx, branch ->
PullRequest(
title = getBranchTitles()[idx],
_base = getBaseBranches()[idx].copy(),
_head = branch.copy()
base = getBaseBranches()[idx].copy(),
head = branch.copy()
)
}
return prMarker.markTitlesOf(prs)
Expand Down Expand Up @@ -69,8 +69,8 @@ class Branches(
private fun getBranchTitles(): List<String> = branches.mapIndexed { idx, br ->
val (firstName, lastName, _, iterationNr, pairingPartner) = br.parts()
val titleParts = listOf(
firstName.capitalize(),
lastName.capitalize(),
firstName.replaceFirstChar { it.titlecase() },
lastName.replaceFirstChar { it.titlecase() },
"Iteration",
iterationNr,
"/",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
package pullrequestfactory.domain.pullrequests

import kotlinx.serialization.Serializable

@Serializable
data class GetPullRequest(val number: Int, val title: String)
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@ import pullrequestfactory.domain.branches.Branch

data class PullRequest(
val title: String,
private val _base: Branch,
private val _head: Branch
val base: Branch,
val head: Branch,
) {

val base: String = _base.name
val head: String = _head.name

fun markTitleWhenNextHasNewIteration(nextPr: PullRequest) = when {
nextPr.hasNewIteration() -> markTitle()
else -> this.copy()
}

private fun hasNewIteration() = _base.iterationNr() < _head.iterationNr()
private fun hasNewIteration() = base.iterationNr() < head.iterationNr()

fun markTitle() = this.copy(title = "$title [PR]")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CloseCommand(
val httpClient = KhttpClientStats(KhttpClient(githubToken))
ClosePullRequestsPrograms(
args.ui,
GithubAPIClient(httpClient, args.baseUrl, args.repoUrl, args.ui),
GithubAPIClient(httpClient, args.baseUrl, args.repoUrl, args.ui, args.jsonSerizalizer),
httpClient,
candidate,
debug
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/pullrequestfactory/io/clikt/CommandArgs.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package pullrequestfactory.io.clikt

import kotlinx.serialization.json.Json
import pullrequestfactory.domain.uis.UI

class CommandArgs(
val baseUrl: String,
repoPath: String,
val userPropertiesFile: String,
val ui: UI
val ui: UI,
val jsonSerizalizer: Json
) {
val repoUrl = baseUrl + repoPath
}
2 changes: 1 addition & 1 deletion src/main/kotlin/pullrequestfactory/io/clikt/OpenCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class OpenCommand(
val pps = listOf(pp1, pp2, pp3, pp4, pp5, pp6, pp7)
OpenPullRequestsProgram(
args.ui,
GithubAPIClient(httpClient, args.baseUrl, args.repoUrl, args.ui),
GithubAPIClient(httpClient, args.baseUrl, args.repoUrl, args.ui, args.jsonSerizalizer),
httpClient,
isLastFinished,
candidate,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package pullrequestfactory.io.programs.impl

import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializer
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import java.time.Instant

@ExperimentalSerializationApi
@Serializer(forClass = Instant::class)
object InstantSerializer : KSerializer<Instant> {

override val descriptor: SerialDescriptor =
PrimitiveSerialDescriptor(serialName = "Instant", kind = PrimitiveKind.LONG)

override fun serialize(encoder: Encoder, value: Instant) {
encoder.encodeString("${value.toEpochMilli()}")
}

override fun deserialize(decoder: Decoder): Instant {
return Instant.ofEpochSecond(decoder.decodeLong())
}

}
6 changes: 5 additions & 1 deletion src/main/kotlin/pullrequestfactory/io/programs/impl/Rate.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package pullrequestfactory.io.programs.impl

import kotlinx.serialization.Contextual
import kotlinx.serialization.Serializable
import java.time.Instant

data class Rate(val limit: Int, val remaining: Int, val reset: Instant, val used: Int)
@Serializable
data class Rate(val limit: Int, val remaining: Int, @Contextual val reset: Instant, val used: Int)

Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package pullrequestfactory.io.programs.impl

import kotlinx.serialization.Serializable
import java.time.Instant
import java.time.LocalDateTime
import java.time.ZoneOffset
import java.time.format.DateTimeFormatter

@Serializable
data class RateLimit(val rate: Rate) {

fun localResetDateTime() = toLocalDateTime(rate.reset)
Expand Down
Loading