protected override void ProcessRecord()
        {
            base.ProcessRecord();
            UpdateReferenceRequest request;

            try
            {
                request = new UpdateReferenceRequest
                {
                    WorkspaceId            = WorkspaceId,
                    ApplicationKey         = ApplicationKey,
                    ReferenceKey           = ReferenceKey,
                    UpdateReferenceDetails = UpdateReferenceDetails,
                    OpcRequestId           = OpcRequestId,
                    IfMatch       = IfMatch,
                    OpcRetryToken = OpcRetryToken
                };

                response = client.UpdateReference(request).GetAwaiter().GetResult();
                WriteOutput(response, response.Reference);
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
Exemplo n.º 2
0
        public static void Commit(string originmdPath, string modifiedPath, string repoName)
        {
            Console.WriteLine("******************Six steps for Commit***************************");
            //get reference & tree to commit
            string url_getRef    = url_Head + repoName + url_getRefTail;
            string url_getCommit = url_Head + repoName + url_getCommitTail;
            string parent_sha    = JObject.Parse(Get(url_getRef, new Dictionary <string, string>()))["object"]["sha"].ToString();
            string baseTree_sha  = JObject.Parse(Get(url_getCommit + parent_sha, new Dictionary <string, string>()))["tree"]["sha"].ToString();

            //create a  blob
            string            url_createBlob    = url_Head + repoName + url_createBlobTail;
            StreamReader      sr                = new StreamReader(originmdPath, Encoding.GetEncoding("utf-8"));
            CreateBlobRequest createBlobRequest = new CreateBlobRequest
            {
                Content  = sr.ReadToEnd(),
                Encoding = "utf-8"
            };
            string createBlobBody = JsonConvert.SerializeObject(createBlobRequest);
            string blob_sha       = JObject.Parse(Post(url_createBlob, createBlobBody))["sha"].ToString();

            //create a new tree for commit
            string            url_createTree    = url_Head + repoName + url_createTreeTail;
            CreateTreeRequest createTreeRequest = new CreateTreeRequest
            {
                BaseTree = baseTree_sha,
                Tree     = new TreeNode[] {
                    new TreeNode {
                        Path = modifiedPath,
                        Mode = "100644",
                        Type = "blob",
                        Sha  = blob_sha
                    }
                }
            };
            string createTreeBody = JsonConvert.SerializeObject(createTreeRequest);
            string treeSubmit_sha = JObject.Parse(Post(url_createTree, createTreeBody))["sha"].ToString();

            //create a  new commit
            string url_createCommit = url_Head + repoName + url_createCommitTail;
            CreateCommitRequest createCommitRequest = new CreateCommitRequest
            {
                Message = "Commit automatically!",
                Parents = new string[] { parent_sha },
                Tree    = treeSubmit_sha
            };
            string createCommitBody = JsonConvert.SerializeObject(createCommitRequest);
            string createSubmit_sha = JObject.Parse(Post(url_createCommit, createCommitBody))["sha"].ToString();

            //update reference
            string url_updateRef = url_Head + repoName + url_updateRefTail;
            UpdateReferenceRequest updateReferenceRequest = new UpdateReferenceRequest
            {
                Sha   = createSubmit_sha,
                Force = true
            };
            string updateReferenceBody = JsonConvert.SerializeObject(updateReferenceRequest);
            string updateRef_res       = Post(url_updateRef, updateReferenceBody).ToString();
        }
Exemplo n.º 3
0
        private static void Commit()
        {
            Console.WriteLine("******************Six steps for Commit***************************");
            //get reference & tree to commit
            string parent_sha   = JObject.Parse(Get(url_getRef, new Dictionary <string, string>()))["object"]["sha"].ToString();
            string baseTree_sha = JObject.Parse(Get(url_getCommit + parent_sha, new Dictionary <string, string>()))["tree"]["sha"].ToString();

            //create a  blob
            StreamReader      sr = new StreamReader(sourceFile, Encoding.GetEncoding("utf-8"));
            CreateBlobRequest createBlobRequest = new CreateBlobRequest
            {
                Content  = sr.ReadToEnd(),
                Encoding = "utf-8"
            };
            string createBlobBody = JsonConvert.SerializeObject(createBlobRequest);
            string blob_sha       = JObject.Parse(Post(url_createBlob, createBlobBody))["sha"].ToString();

            //create a new tree for commit
            CreateTreeRequest createTreeRequest = new CreateTreeRequest
            {
                BaseTree = baseTree_sha,
                Tree     = new TreeNode[] {
                    new TreeNode {
                        Path = @"node-azure-tools.md",
                        Mode = "100644",
                        Type = "blob",
                        Sha  = blob_sha
                    }
                }
            };
            string createTreeBody = JsonConvert.SerializeObject(createTreeRequest);
            string treeSubmit_sha = JObject.Parse(Post(url_createTree, createTreeBody))["sha"].ToString();

            //create a  new commit
            CreateCommitRequest createCommitRequest = new CreateCommitRequest
            {
                Message = "Commit automatically!",
                Parents = new string[] { parent_sha },
                Tree    = treeSubmit_sha
            };
            string createCommitBody = JsonConvert.SerializeObject(createCommitRequest);
            string createSubmit_sha = JObject.Parse(Post(url_createCommit, createCommitBody))["sha"].ToString();

            //update reference
            UpdateReferenceRequest updateReferenceRequest = new UpdateReferenceRequest
            {
                Sha   = createSubmit_sha,
                Force = true
            };
            string updateReferenceBody = JsonConvert.SerializeObject(updateReferenceRequest);
            string updateRef_res       = Post(url_updateRef, updateReferenceBody).ToString();
        }