From 3cabbbd2c41257eaae27246dac209243042d0f78 Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Wed, 5 Jun 2024 16:03:39 +0300 Subject: [PATCH] #2025 skip if repo is absent --- src/main/java/com/rultor/Routine.java | 13 +++++++---- .../agents/github/qtn/DefaultBranch.java | 22 +++++++++++++++++++ .../java/com/rultor/profiles/Profiles.java | 8 ++++++- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/rultor/Routine.java b/src/main/java/com/rultor/Routine.java index e1745080aa..ae4d3e12b0 100644 --- a/src/main/java/com/rultor/Routine.java +++ b/src/main/java/com/rultor/Routine.java @@ -35,6 +35,7 @@ import com.jcabi.github.Github; import com.jcabi.log.Logger; import com.rultor.agents.Agents; +import com.rultor.agents.github.qtn.DefaultBranch; import com.rultor.profiles.Profiles; import com.rultor.spi.Profile; import com.rultor.spi.Pulse; @@ -197,10 +198,14 @@ private int process(final List active) throws IOException { int total = 0; for (final Talk talk : active) { ++total; - final Profile profile = profiles.fetch(talk); - this.agents.agent(talk, profile).execute(talk); - if (total > Routine.MAX_TALKS) { - break; + try { + final Profile profile = profiles.fetch(talk); + this.agents.agent(talk, profile).execute(talk); + if (total > Routine.MAX_TALKS) { + break; + } + } catch (final DefaultBranch.RepoNotFoundException ex) { + Logger.warn(this, "The repo not found: %[exception]s", ex); } } this.agents.closer().execute(this.talks); diff --git a/src/main/java/com/rultor/agents/github/qtn/DefaultBranch.java b/src/main/java/com/rultor/agents/github/qtn/DefaultBranch.java index aa7d01791e..9674a31aa1 100644 --- a/src/main/java/com/rultor/agents/github/qtn/DefaultBranch.java +++ b/src/main/java/com/rultor/agents/github/qtn/DefaultBranch.java @@ -61,6 +61,28 @@ public String toString() { String.format("Repo %s has no default branch", this.repo), ex ); + } catch (final AssertionError ex) { + throw new RepoNotFoundException(this.repo.coordinates().toString(), ex); + } + } + + /** + * When repo is not found. + * @since 2.1 + */ + public static class RepoNotFoundException extends RuntimeException { + /** + * Serialization marker. + */ + private static final long serialVersionUID = -3860028281726793188L; + + /** + * Ctor. + * @param name Name of repo + * @param exp Original problem + */ + public RepoNotFoundException(final String name, final Throwable exp) { + super(String.format("Most probably the repo %s doesn't exist", name), exp); } } } diff --git a/src/main/java/com/rultor/profiles/Profiles.java b/src/main/java/com/rultor/profiles/Profiles.java index c0fe08e129..6e9f8a1d70 100644 --- a/src/main/java/com/rultor/profiles/Profiles.java +++ b/src/main/java/com/rultor/profiles/Profiles.java @@ -32,11 +32,13 @@ import com.jcabi.aspects.Cacheable; import com.jcabi.aspects.Immutable; import com.jcabi.github.Github; +import com.jcabi.github.Repo; import com.jcabi.github.RtGithub; import com.jcabi.github.wire.RetryCarefulWire; import com.jcabi.manifests.Manifests; import com.jcabi.xml.XML; import com.rultor.agents.github.TalkIssues; +import com.rultor.agents.github.qtn.DefaultBranch; import com.rultor.spi.Profile; import com.rultor.spi.Talk; import java.io.IOException; @@ -168,8 +170,12 @@ private Profile fetch(final XML xml) throws IOException { final Profile profile; final List type = xml.xpath("//request/type/text()"); if (type.isEmpty() || !Profiles.MERGE.equals(type.get(0))) { + final Repo repo = new TalkIssues( + Profiles.github(), xml + ).get().repo(); profile = new GithubProfile( - new TalkIssues(Profiles.github(), xml).get().repo() + repo, + new DefaultBranch(repo).toString() ); } else { profile = this.merged(