Beispiel #1
0
        protected void TryLogin(string apiPath, string password)
        {
            apiPath = apiPath.Trim();
            if (apiPath[apiPath.Length - 1] == '/')
            {
                apiPath = apiPath.Remove(apiPath.Length - 1);
            }

            var request = UnityWebRequest.Get(apiPath + "/user");

            request.SetRequestHeader("PRIVATE-TOKEN", password);

            var async = request.SendWebRequest();

            async.completed += op =>
            {
                UnityWebRequestAsyncOperation asyncop = op as UnityWebRequestAsyncOperation;
                if (asyncop.webRequest.isHttpError)
                {
                    Debug.Log(asyncop.webRequest.error + " :: " + asyncop.webRequest.downloadHandler.text);
                    GetAuthToken();
                }
                else
                {
                    GitlabUserData user = JsonUtility.FromJson <GitlabUserData>(asyncop.webRequest.downloadHandler.text);

                    _userID = user.id;

                    var setting = BugReporterPlugin.settings.GetBackendSettings(backendName);
                    setting.token   = password;
                    setting.apiPath = apiPath;

                    _apiPath    = apiPath;
                    _token      = password;
                    _isLoggedIn = true;
                    BugReporterPlugin.SaveSettings();

                    Debug.LogFormat("[Gitlab Backend] : Logged in as user " + user.name);

                    // Gitlab have an image uploader setup by default
                    BugReporterPlugin.SetupImageUploader(GitlabImageUploader.imgUploaderName);

                    if (setting.projectPath != "")
                    {
                        SetupProjectInfo();
                    }

                    if (OnPostInit != null)
                    {
                        OnPostInit.Invoke();
                    }
                }
            };
        }
Beispiel #2
0
        protected void TryLogin(string password)
        {
            var request = UnityWebRequest.Get(baseURL + "/user");

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

            var async = request.SendWebRequest();

            async.completed += op =>
            {
                UnityWebRequestAsyncOperation asyncop = op as UnityWebRequestAsyncOperation;
                if (asyncop.webRequest.isHttpError)
                {
                    Debug.Log(asyncop.webRequest.error);
                    GetAuthToken();
                }
                else
                {
                    string response = asyncop.webRequest.GetResponseHeader("X-OAuth-Scopes");
                    if (response.Contains("repo"))
                    {
                        GithubUserData user = JsonUtility.FromJson <GithubUserData>(asyncop.webRequest.downloadHandler.text);

                        _userID = user.id;

                        var setting = BugReporterPlugin.settings.GetBackendSettings(backendName);
                        setting.token = password;
                        _token        = password;
                        _isLoggedIn   = true;
                        BugReporterPlugin.SaveSettings();

                        Debug.LogFormat("[Github Backend] : Logged in as user " + user.login);

                        if (setting.projectPath != "")
                        {
                            SetupProjectInfo();
                        }

                        if (OnPostInit != null)
                        {
                            OnPostInit.Invoke();
                        }
                    }
                    else
                    {
                        Debug.LogError("[Github Backend] : This Personal Access token don't have the repo access");
                        GetAuthToken();
                    }
                }
            };
        }
        public override void UploadFile(byte[] data, System.Action <bool, string> onUploadFinished)
        {
            var settings = BugReporterPlugin.settings.GetImageUploaderSetting(_uploaderName);

            if (settings.authentification == "")
            {
                var tokenEnter = EditorWindow.GetWindow <ImgurTokenEntry>();
                tokenEnter.onEntered = win =>
                {
                    settings.authentification = win.appID;
                    BugReporterPlugin.SaveSettings();
                    InternalUpload(data, onUploadFinished);
                };
            }
            else
            {
                InternalUpload(data, onUploadFinished);
            }
        }
        void InternalUpload(byte[] data, System.Action <bool, string> onUploadFinished)
        {
            var request = new UnityWebRequest("https://api.imgur.com/3/image", UnityWebRequest.kHttpVerbPOST);

            request.SetRequestHeader("Authorization", "Client-ID 7b2138351689000");

            request.uploadHandler             = new UploadHandlerRaw(data);
            request.uploadHandler.contentType = "image/png";

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

            var async = request.SendWebRequest();

            async.completed += op =>
            {
                UnityWebRequestAsyncOperation asyncop = op as UnityWebRequestAsyncOperation;
                if (asyncop.webRequest.isHttpError)
                {
                    Debug.LogErrorFormat("[Imgur Uploader] Error {0} : {1}", asyncop.webRequest.responseCode, asyncop.webRequest.error);

                    if (asyncop.webRequest.responseCode == 401)
                    {//unauthorized error, the access token is probably invalid, so remove it from the settings.
                        var settings = BugReporterPlugin.settings.GetImageUploaderSetting(_uploaderName);
                        settings.authentification = "";
                        BugReporterPlugin.SaveSettings();
                    }

                    onUploadFinished(false, "");
                }
                else
                {
                    DataWrapper <ImgurUploadResponse> response = JsonUtility.FromJson <DataWrapper <ImgurUploadResponse> >(asyncop.webRequest.downloadHandler.text);

                    onUploadFinished(true, response.data.link);
                }
            };
        }
        private void OnGUI()
        {
            entry.title = EditorGUILayout.TextField("Title", entry.title);
            EditorGUILayout.LabelField("Description");
            entry.description = EditorGUILayout.TextArea(entry.description, GUILayout.MinHeight((150)));

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Assignees");
            if (EditorGUILayout.DropdownButton(new GUIContent(entry.assigneesString), FocusType.Keyboard))
            {
                GenericMenu menu = new GenericMenu();

                var users = BugReporterPlugin.users;
                foreach (var user in users)
                {
                    menu.AddItem(new GUIContent(user.name), ArrayUtility.Contains(entry.assignees, user), ToggleUserAssignee, user);
                }

                menu.ShowAsContext();
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Labels");
            if (EditorGUILayout.DropdownButton(new GUIContent(entry.labelsString), FocusType.Keyboard))
            {
                GenericMenu menu = new GenericMenu();

                var labels = BugReporterPlugin.labels;
                foreach (var label in labels)
                {
                    menu.AddItem(new GUIContent(label), ArrayUtility.Contains(entry.labels, label), ToggleLabel, label);
                }

                menu.ShowAsContext();
            }
            EditorGUILayout.EndHorizontal();

            if (severityMax != 0)
            {
                entry.severity = EditorGUILayout.IntSlider("Severity", entry.severity, 0, severityMax);
            }

            EditorGUILayout.BeginHorizontal();

            logPosition = EditorGUILayout.Toggle("Log Position", logPosition);

            if (BugReporterPlugin.settings.currentImageUploader == "")
            {
                int selected = EditorGUILayout.Popup("Image uploader", -1, BugReporterPlugin.GetImageUploaderName());
                if (selected != -1)
                {
                    BugReporterPlugin.SetupImageUploader(BugReporterPlugin.GetImageUploaderName()[selected]);
                }
            }
            else
            {
                uploadScreenshot = EditorGUILayout.Toggle("Upload Screenshot", uploadScreenshot);
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button("Send"))
            {
                onWindowClosed(this);
                Close();
            }

            if (GUILayout.Button("Cancel"))
            {
                Close();
            }

            EditorGUILayout.EndHorizontal();
        }
Beispiel #6
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);
                }
            };
        }
Beispiel #7
0
 // /!\ Don't forget to add a static constructor to register the backend !!
 static GithubBugReportBackend()
 {
     BugReporterPlugin.RegisterBackend(backendName, new GithubBugReportBackend());
 }
 static ImgurUploader()
 {
     BugReporterPlugin.RegisterImageUploader(_uploaderName, new ImgurUploader());
 }
Beispiel #9
0
 static GitlabImageUploader()
 {
     BugReporterPlugin.RegisterImageUploader(imgUploaderName, new GitlabImageUploader());
 }