【问题标题】:Determin if GitHub Issue Already Exists确定 GitHub 问题是否已经存在
【发布时间】:2017-08-08 00:07:26
【问题描述】:

我一直在编写一个错误报告器,以自动将我的 Minecraft 模组中的异常报告到我的 GitHub 问题页面。它可以工作,但是我检查问题是否已经存在的代码不起作用。我正在使用jcabi 与 GitHub 进行交互。如果您需要更多信息,请告诉我。谢谢!

确定问题是否已经存在的代码:

private static boolean DoesIssueAlreadyExist(String Title, String Report)
{
    try
    {
        int i = 0;
        int size = GetNumberOfIssues();
        Issue.Smart Current;

        while (i != size)
        {
            Current = new Issue.Smart(repo.issues().get(i));

            if (Current.title() == Title && Current.body() == Report)
            {
                    return true;
            }

            i++;
        }

        return false;

    }
    catch (Exception e)
    {
        e.printStackTrace();
        return false;
    }
}

开始我的消息生成和问题创建过程的代码:

private static Github github = new RtGithub(Secure.Token);
private static Repo repo = github.repos().get( new Coordinates.Simple("SneakyTactician/BIGB2"));

public static void Report(Exception ToReport)
{
    try 
    {       
        //The title for the issue.
        String Title = ToReport.getMessage();
        //Generates a message for the issue. 
        String Report = GetMessage(ToReport);

        if (!DoesIssueAlreadyExist(Title, Report))
        {   

        Issue TheIssue = repo.issues().create(Title, Report);
        Issue.Smart a = new Issue.Smart(TheIssue);
        a.assign("SneakyTactician");

        a.labels().add(extracted());
        }
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
}

示例问题标题:

/ 零

示例问题正文:

java.lang.ArithmeticException: / by zero
at sneaky.main.Startup.preInit(Startup.java:28)
at sneaky.main.BIGB2.preInit(BIGB2.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:641)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:246)
at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:224)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:147)
at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:628)
at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:268)
at net.minecraft.client.Minecraft.func_71384_a(Minecraft.java:440)
at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:352)
at net.minecraft.client.main.Main.main(SourceFile:124)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

6number 个模组被发现在运行:

我的世界 1.11.2

我的世界编码器包 9.19

锻造模组加载器 8.0.99.99

Minecraft Forge 13.20.0.2228

mercurius_updater 1.0

因为我无聊 1.0

【问题讨论】:

    标签: java git error-reporting jcabi


    【解决方案1】:

    经过数小时的困惑和挫折后,我想通了!以下方法检查您的 GitHub 问题页面上是否已存在该问题。

    /**
     * Determines if the exception has already been posted to the issue page.
     * Returns false if an error occurs.
     * @param e
     * @return
     */
    private static boolean DoesIssueAlreadyExist(String Title, String Report)
    {  
      try
        {
            EnumMap<Qualifier, String> qualifiers = new EnumMap<Qualifier, String>(Issues.Qualifier.class);
    
            Iterable<Issue> Issues = repo.issues().search(Sort.CREATED, Order.DESC, qualifiers);
    
            Issue.Smart current;
    
            long size = Iterables.size(Issues);
    
            int i = 0;
    
    
            while (i != size)
            {
                current = new Issue.Smart(Issues.iterator().next());
    
                if (current.title().contains(Title) && current.body().contains(Report))
                { 
                    return true;
                }
    
                i++;
            }
    
            return false;
    
        }
        catch (Exception e)
        {
            e.printStackTrace();
            return true;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2011-05-18
      • 2016-06-21
      • 2023-01-25
      • 1970-01-01
      • 1970-01-01
      • 2022-07-28
      • 1970-01-01
      • 2012-11-24
      • 2010-09-07
      相关资源
      最近更新 更多