Beispiel #1
0
        public override void Load()
        {
            context.LogInfo(this, String.Format("Loading user account: Id={0}", this.Id));

            base.Load();

            //Github information
            if (this.Name != null)
            {
                context.LogInfo(this, String.Format("Loading user account: Name={0}", this.Name));
                try{
                    GithubUserResponse usr = this.Client.GetUser(this.Name);
                    this.Identifier = usr.id.ToString();
                    this.Avatar     = usr.avatar_url;
                    this.Email      = usr.email;
                    // ...
                    // we can get more if we want to

                    //we store in case of changes
                    this.Store();
                }catch (Exception e) {
                    this.Avatar     = null;
                    this.Identifier = null;
                    context.LogError(this, String.Format("{0} : {1}", e.Message, e.StackTrace));
                }
            }
        }
Beispiel #2
0
        public void RemoveCollaboratorFromRepo(string org, string repo, string username)
        {
            var            result  = new GithubUserResponse();
            HttpWebRequest request = CreateWebRequest(ApiBaseUrl + "/repos/" + org + "/" + repo + "/collaborators/" + username, "DELETE");

            using (var httpResponse = (HttpWebResponse)request.GetResponse()) {
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) {
                    string json = streamReader.ReadToEnd();
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Gets the user github profile
        /// </summary>
        /// <returns>The user.</returns>
        /// <param name="githubName">Github name.</param>
        public GithubUserResponse GetUser(string githubName)
        {
            GithubUserResponse result  = new GithubUserResponse();
            HttpWebRequest     request = CreateWebRequest(ApiBaseUrl + "/users/" + githubName, "GET", null, null);

            using (var httpResponse = (HttpWebResponse)request.GetResponse()) {
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) {
                    string json = streamReader.ReadToEnd();
                    result = JsonSerializer.DeserializeFromString <GithubUserResponse> (json);
                }
            }
            return(result);
        }
Beispiel #4
0
        public void AddCollaboratorToRepo(string org, string repo, string username, string permission)
        {
            var            result  = new GithubUserResponse();
            HttpWebRequest request = CreateWebRequest(ApiBaseUrl + "/repos/" + org + "/" + repo + "/collaborators/" + username, "PUT");

            string jsonbody = "{\"permission\":\"" + permission + "\"}";

            using (var streamWriter = new StreamWriter(request.GetRequestStream())) {
                streamWriter.Write(jsonbody);
                streamWriter.Flush();
                streamWriter.Close();

                using (var httpResponse = (HttpWebResponse)request.GetResponse()) {
                    using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) {
                        string json = streamReader.ReadToEnd();
                        result = JsonSerializer.DeserializeFromString <GithubUserResponse>(json);
                    }
                }
            }
        }