private void OnEnable()
        {
            entry = new BugReporterPlugin.IssueEntry();

            BugReporterPlugin.backend.UsePriority(out severityMax, out entry.severity);

            if (Application.isPlaying)
            {
                timeScaleSaved = Time.timeScale;
                Time.timeScale = 0;
            }
        }
Example #2
0
        public override void LogIssue(BugReporterPlugin.IssueEntry issue)
        {
            issue.description = issue.description.Replace("\n", "\\n");

            StringBuilder data = new StringBuilder();

            data.AppendFormat("{{\"title\": \"{0}\", \"body\": \"{1}\"", issue.title, issue.description);

            if (issue.assignees.Length > 0)
            {
                data.Append(",\"assignees\":[");

                for (int i = 0; i < issue.assignees.Length; ++i)
                {
                    data.AppendFormat("\"{0}\"", issue.assignees[i].name);
                    if (i != issue.assignees.Length - 1)
                    {
                        data.Append(",");
                    }
                }
                data.Append("]");
            }

            if (issue.labels.Length > 0)
            {
                data.Append(",\"labels\":[");

                for (int i = 0; i < issue.labels.Length; ++i)
                {
                    data.AppendFormat("\"{0}\"", issue.labels[i]);
                    if (i != issue.labels.Length - 1)
                    {
                        data.Append(",");
                    }
                }
                data.Append("]");
            }

            data.Append("}");

            var settings = BugReporterPlugin.settings.GetBackendSettings(backendName);

            var request = new UnityWebRequest(baseURL + "/repos/" + settings.projectPath + "/issues", "POST");

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

            request.uploadHandler             = new UploadHandlerRaw(System.Text.Encoding.UTF8.GetBytes(data.ToString()));
            request.uploadHandler.contentType = "application/json";

            request.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer();

            var async = request.SendWebRequest();

            async.completed += op =>
            {
                UnityWebRequestAsyncOperation asyncop = op as UnityWebRequestAsyncOperation;
                if (asyncop.webRequest.isHttpError || asyncop.webRequest.responseCode != 201)
                {
                    Debug.LogError("couldn't Post issue to repo " + settings.projectPath);
                    Debug.LogError("Error code : " + async.webRequest.responseCode + "\n Error:\n" + asyncop.webRequest.downloadHandler.text);
                }
                else
                {
                    Debug.Log("Issue posted successfully");
                }
            };
        }
Example #3
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 #4
0
 /// <summary>
 /// Called by the system when the users have logged as issue. All data should be sent to the backend.
 /// Note : the unitybt url will be part of the description at that point if the user asked to log position.
 /// </summary>
 /// <param name="issue"></param>
 public abstract void LogIssue(BugReporterPlugin.IssueEntry issue);