Example #1
0
        public override void RequestIssues(Action <List <BugReporterPlugin.IssueEntry> > requestFinishedCallback, BugReporterPlugin.IssueFilter filter)
        {
            var settings = BugReporterPlugin.settings.GetBackendSettings(backendName);

            string requestURL = baseURL + "/repos/" + settings.projectPath + "/issues?";

            if (filter.user != null)
            {
                requestURL += "assignee=" + filter.user.name + "&";
            }

            if (filter.labels != null && filter.labels.Length > 0)
            {
                requestURL += "labels=" + filter.labelCommaString;
            }

            var request = UnityWebRequest.Get(requestURL);

            request.SetRequestHeader("Accept", "application/vnd.github.v3+json");
            request.SetRequestHeader("Authorization", "token " + _token);

            var async = request.SendWebRequest();

            async.completed += op =>
            {
                UnityWebRequestAsyncOperation asyncop = op as UnityWebRequestAsyncOperation;
                if (asyncop.webRequest.isHttpError)
                {
                    Debug.LogError("couldn't get issues for repo " + settings.projectPath);
                    Debug.LogError(asyncop.webRequest.error);
                }
                else
                {
                    _issues.Clear();

                    string            newJson = "{ \"array\": " + asyncop.webRequest.downloadHandler.text + "}";
                    GithubIssueData[] issues  = JsonUtility.FromJson <Wrapper <GithubIssueData> >(newJson).array;

                    for (int i = 0; i < issues.Length; ++i)
                    {
                        BugReporterPlugin.IssueEntry newEntry = new BugReporterPlugin.IssueEntry();
                        newEntry.title       = issues[i].title;
                        newEntry.description = issues[i].body;
                        newEntry.webUrl      = issues[i].url;

                        newEntry.assignees = new BugReporterPlugin.UserEntry[0];
                        if (issues[i].assignees != null)
                        {
                            for (int j = 0; j < issues[i].assignees.Length; ++j)
                            {
                                //TODO : this is terrible. Use some dictionnary maybe or better typing to avoid so much silly conversion
                                var userEntry = BugReporterPlugin.GetUserInfoByID(issues[i].assignees[j].id.ToString());
                                if (userEntry != null)
                                {
                                    ArrayUtility.Add(ref newEntry.assignees, userEntry);
                                }
                            }
                        }

                        newEntry.labels = new string[0];
                        if (issues[i].labels != null)
                        {
                            for (int j = 0; j < issues[i].labels.Length; ++j)
                            {
                                ArrayUtility.Add(ref newEntry.labels, issues[i].labels[j].name);
                            }
                        }

                        newEntry.RetrieveDataFromUnityURL();
                        newEntry.BuildCommaStrings();

                        _issues.Add(newEntry);
                    }

                    requestFinishedCallback(_issues);
                }
            };
        }
Example #2
0
 /// <summary>
 /// Called by the system when need to recover issues/bug. It should call requestFinishedCallback once all issue are reconvered.
 /// </summary>
 /// <param name="requestFinishedCallback"></param>
 /// <param name="filter">An additional filter, to filter for a specific user and/or a set of labels</param>
 public abstract void RequestIssues(System.Action <List <BugReporterPlugin.IssueEntry> > requestFinishedCallback, BugReporterPlugin.IssueFilter filter);