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

Include all release related links in PR body #1308

Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2018-2020 Scala Steward contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.scalasteward.core.data

import org.http4s.Uri

sealed trait ReleaseRelatedUrl {
def url: Uri
}

object ReleaseRelatedUrl {
final case class CustomChangelog(url: Uri) extends ReleaseRelatedUrl
final case class CustomReleaseNotes(url: Uri) extends ReleaseRelatedUrl
final case class GitHubReleaseNotes(url: Uri) extends ReleaseRelatedUrl
final case class VersionDiff(url: Uri) extends ReleaseRelatedUrl
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,20 +140,16 @@ final class NurtureAlg[F[_]](
artifactIdToUrl <- coursierAlg.getArtifactIdUrlMapping(
Scope(data.update.dependencies.toList, resolvers)
)
branchCompareUrl <- artifactIdToUrl
releaseRelatedUrls <- artifactIdToUrl
.get(data.update.mainArtifactId)
.flatTraverse(vcsExtraAlg.getBranchCompareUrl(_, data.update))
releaseNoteUrl <- artifactIdToUrl
.get(data.update.mainArtifactId)
.flatTraverse(vcsExtraAlg.getReleaseNoteUrl(_, data.update))
.traverse(vcsExtraAlg.getReleaseRelatedUrls(_, data.update))
branchName = vcs.createBranch(config.vcsType, data.fork, data.update)
migrations <- migrationAlg.findMigrations(data.update)
requestData = NewPullRequestData.from(
data,
branchName,
artifactIdToUrl,
branchCompareUrl,
releaseNoteUrl,
releaseRelatedUrls.getOrElse(List.empty),
migrations
)
pr <- vcsApiAlg.createPullRequest(data.repo, requestData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ package org.scalasteward.core.vcs
import cats.Monad
import cats.implicits._
import org.http4s.Uri
import org.scalasteward.core.data.Update
import org.scalasteward.core.data.{ReleaseRelatedUrl, Update}
import org.scalasteward.core.util.HttpExistenceClient
import org.scalasteward.core.vcs

trait VCSExtraAlg[F[_]] {
def getBranchCompareUrl(repoUrl: Uri, update: Update): F[Option[Uri]]
def getReleaseNoteUrl(repoUrl: Uri, update: Update): F[Option[Uri]]
def getReleaseRelatedUrls(repoUrl: Uri, update: Update): F[List[ReleaseRelatedUrl]]
}

object VCSExtraAlg {
Expand All @@ -34,10 +33,10 @@ object VCSExtraAlg {
existenceClient: HttpExistenceClient[F],
F: Monad[F]
): VCSExtraAlg[F] = new VCSExtraAlg[F] {
override def getBranchCompareUrl(repoUrl: Uri, update: Update): F[Option[Uri]] =
vcs.possibleCompareUrls(repoUrl, update).findM(existenceClient.exists)
override def getReleaseRelatedUrls(repoUrl: Uri, update: Update): F[List[ReleaseRelatedUrl]] =
vcs
.possibleReleaseRelatedUrls(repoUrl, update)
.filterA(releaseRelatedUrl => existenceClient.exists(releaseRelatedUrl.url))

override def getReleaseNoteUrl(repoUrl: Uri, update: Update): F[Option[Uri]] =
vcs.possibleChangelogUrls(repoUrl, update).findM(existenceClient.exists)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import cats.implicits._
import io.circe.Encoder
import io.circe.generic.semiauto._
import org.http4s.Uri
import org.scalasteward.core.data.{GroupId, SemVer, Update}
import org.scalasteward.core.data.{GroupId, ReleaseRelatedUrl, SemVer, Update}
import org.scalasteward.core.git
import org.scalasteward.core.git.Branch
import org.scalasteward.core.nurture.UpdateData
Expand All @@ -42,8 +42,7 @@ object NewPullRequestData {
def bodyFor(
update: Update,
artifactIdToUrl: Map[String, Uri],
branchCompareUrl: Option[Uri],
releaseNoteUrl: Option[Uri],
releaseRelatedUrls: List[ReleaseRelatedUrl],
migrations: List[Migration]
): String = {
val artifacts = artifactsWithOptionalUrl(update, artifactIdToUrl)
Expand All @@ -52,8 +51,8 @@ object NewPullRequestData {
val labels =
Nel.fromList(List(updateType(update)) ++ semVerLabel(update).toList ++ migrationLabel.toList)

s"""|Updates $artifacts ${fromTo(update, branchCompareUrl)}.
|${releaseNote(releaseNoteUrl).getOrElse("")}
s"""|Updates $artifacts ${fromTo(update)}.
|${releaseNote(releaseRelatedUrls).getOrElse("")}
|
|I'll automatically update this PR to resolve conflicts as long as you don't change it yourself.
|
Expand All @@ -77,18 +76,25 @@ object NewPullRequestData {
"library-update"
}

def releaseNote(releaseNoteUrl: Option[Uri]): Option[String] =
releaseNoteUrl.map { url =>
s"[Release Notes/Changelog](${url.renderString})"
}
def releaseNote(releaseRelatedUrls: List[ReleaseRelatedUrl]): Option[String] =
if (releaseRelatedUrls.isEmpty) None
else
releaseRelatedUrls
.map { url =>
url match {
case ReleaseRelatedUrl.CustomChangelog(url) => s"[Changelog](${url.renderString})"
case ReleaseRelatedUrl.CustomReleaseNotes(url) =>
s"[Release Notes](${url.renderString})"
case ReleaseRelatedUrl.GitHubReleaseNotes(url) =>
s"[GitHub Release Notes](${url.renderString})"
case ReleaseRelatedUrl.VersionDiff(url) => s"[Version Diff](${url.renderString})"
}
}
.mkString(" - ")
.some

def fromTo(update: Update, branchCompareUrl: Option[Uri]): String = {
val fromToVersions = s"from ${update.currentVersion} to ${update.nextVersion}"
branchCompareUrl match {
case None => fromToVersions
case Some(compareUrl) => s"[${fromToVersions}](${compareUrl.renderString})"
}
}
def fromTo(update: Update): String =
s"from ${update.currentVersion} to ${update.nextVersion}"

def artifactsWithOptionalUrl(update: Update, artifactIdToUrl: Map[String, Uri]): String =
update match {
Expand Down Expand Up @@ -146,17 +152,15 @@ object NewPullRequestData {
data: UpdateData,
branchName: String,
artifactIdToUrl: Map[String, Uri] = Map.empty,
branchCompareUrl: Option[Uri] = None,
releaseNoteUrl: Option[Uri] = None,
releaseRelatedUrls: List[ReleaseRelatedUrl] = List.empty,
migrations: List[Migration] = List.empty
): NewPullRequestData =
NewPullRequestData(
title = git.commitMsgFor(data.update),
body = bodyFor(
data.update,
artifactIdToUrl,
branchCompareUrl,
releaseNoteUrl,
releaseRelatedUrls,
migrations
),
head = branchName,
Expand Down
46 changes: 32 additions & 14 deletions modules/core/src/main/scala/org/scalasteward/core/vcs/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import cats.implicits._
import org.http4s.Uri
import org.scalasteward.core.application.SupportedVCS
import org.scalasteward.core.application.SupportedVCS.{Bitbucket, BitbucketServer, GitHub, Gitlab}
import org.scalasteward.core.data.Update
import org.scalasteward.core.data.ReleaseRelatedUrl.VersionDiff
import org.scalasteward.core.data.{ReleaseRelatedUrl, Update}
import org.scalasteward.core.vcs.data.Repo

package object vcs {
Expand Down Expand Up @@ -53,45 +54,53 @@ package object vcs {
List(s"v$version", version, s"release-$version")

val possibleChangelogFilenames: List[String] = {
val basenames = List(
val baseNames = List(
"CHANGELOG",
"Changelog",
"changelog",
"CHANGES",
"CHANGES"
)
possibleFilenames(baseNames)
}

val possibleReleaseNotesFilenames: List[String] = {
val baseNames = List(
"ReleaseNotes",
"RELEASES",
"Releases",
"releases"
)
val extensions = List("md", "markdown", "rst")
(basenames, extensions).mapN { case (base, ext) => s"$base.$ext" }
possibleFilenames(baseNames)
}

def possibleCompareUrls(repoUrl: Uri, update: Update): List[Uri] = {
def possibleCompareUrls(repoUrl: Uri, update: Update): List[VersionDiff] = {
val host = repoUrl.host.map(_.value)
val from = update.currentVersion
val to = update.nextVersion

if (host.exists(Set("github.com", "gitlab.com")))
possibleTags(from).zip(possibleTags(to)).map {
case (from1, to1) => repoUrl / "compare" / s"$from1...$to1"
case (from1, to1) => VersionDiff(repoUrl / "compare" / s"$from1...$to1")
}
else if (host.contains_("bitbucket.org"))
possibleTags(from).zip(possibleTags(to)).map {
case (from1, to1) => (repoUrl / "compare" / s"$to1..$from1").withFragment("diff")
case (from1, to1) =>
VersionDiff((repoUrl / "compare" / s"$to1..$from1").withFragment("diff"))
}
else
List.empty
}

def possibleChangelogUrls(repoUrl: Uri, update: Update): List[Uri] = {
def possibleReleaseRelatedUrls(repoUrl: Uri, update: Update): List[ReleaseRelatedUrl] = {
val host = repoUrl.host.map(_.value)
val vcsSpecific =
val github =
if (host.contains_("github.com"))
possibleTags(update.nextVersion).map(tag => repoUrl / "releases" / "tag" / tag)
possibleTags(update.nextVersion).map(tag =>
ReleaseRelatedUrl.GitHubReleaseNotes(repoUrl / "releases" / "tag" / tag)
)
else
List.empty
val files = {
def files(fileNames: List[String]): List[Uri] = {
val maybeSegments =
if (host.exists(Set("github.com", "gitlab.com"))) {
Some(List("blob", "master"))
Expand All @@ -102,9 +111,18 @@ package object vcs {
}
maybeSegments.toList.flatMap { segments =>
val base = segments.foldLeft(repoUrl)(_ / _)
possibleChangelogFilenames.map(name => base / name)
fileNames.map(name => base / name)
}
}
files ++ vcsSpecific
val customChangelog = files(possibleChangelogFilenames).map(ReleaseRelatedUrl.CustomChangelog)
val customReleaseNotes =
files(possibleReleaseNotesFilenames).map(ReleaseRelatedUrl.CustomReleaseNotes)

github ++ customReleaseNotes ++ customChangelog ++ possibleCompareUrls(repoUrl, update)
}

private def possibleFilenames(baseNames: List[String]): List[String] = {
val extensions = List("md", "markdown", "rst")
(baseNames, extensions).mapN { case (base, ext) => s"$base.$ext" }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.http4s.dsl.io._
import org.http4s.implicits._
import org.scalasteward.core.TestInstances.ioLogger
import org.scalasteward.core.TestSyntax._
import org.scalasteward.core.data.Update
import org.scalasteward.core.data.{ReleaseRelatedUrl, Update}
import org.scalasteward.core.mock.MockContext.config
import org.scalasteward.core.util.{HttpExistenceClient, Nel}
import org.scalatest.funsuite.AnyFunSuite
Expand All @@ -32,13 +32,15 @@ class VCSExtraAlgTest extends AnyFunSuite with Matchers {

test("getBranchCompareUrl") {
vcsExtraAlg
.getBranchCompareUrl(uri"https://github.com/foo/foo", updateFoo)
.unsafeRunSync() shouldBe None
.getReleaseRelatedUrls(uri"https://github.com/foo/foo", updateFoo)
.unsafeRunSync() shouldBe List.empty
vcsExtraAlg
.getBranchCompareUrl(uri"https://github.com/foo/bar", updateBar)
.unsafeRunSync() shouldBe Some(uri"https://github.com/foo/bar/compare/v0.1.0...v0.2.0")
.getReleaseRelatedUrls(uri"https://github.com/foo/bar", updateBar)
.unsafeRunSync() shouldBe List(
ReleaseRelatedUrl.VersionDiff(uri"https://github.com/foo/bar/compare/v0.1.0...v0.2.0")
)
vcsExtraAlg
.getBranchCompareUrl(uri"https://github.com/foo/buz", updateBuz)
.unsafeRunSync() shouldBe None
.getReleaseRelatedUrls(uri"https://github.com/foo/buz", updateBuz)
.unsafeRunSync() shouldBe List.empty
}
}
Loading