-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateDirectoryAction.cs
62 lines (54 loc) · 1.85 KB
/
CreateDirectoryAction.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Web;
using Inedo.BuildMaster;
using Inedo.BuildMaster.Extensibility.Actions;
using Inedo.BuildMaster.Web;
namespace Inedo.BuildMasterExtensions.Artifactory
{
[ActionProperties(
"Create Directory",
"Creates a new directory in the specified location.")]
[Tag("Artifactory")]
[CustomEditor(typeof(CreateDirectoryActionEditor))]
public class CreateDirectoryAction : ArtifactoryActionBase
{
[Persistent]
public string DirectoryName {get;set;}
public override string ToString()
{
return string.Format("Create directory named {0} in repository {1}", this.DirectoryName, this.RepositoryKey);
}
public CreateDirectoryAction()
{
this.UsesRepositoryKey = true;
}
internal string Test()
{
return ProcessRemoteCommand(null, null);
}
protected override void Execute()
{
this.ExecuteRemoteCommand(null);
}
protected override string ProcessRemoteCommand(string name, string[] args)
{
return MakeRequest();
}
internal string MakeRequest()
{
string url = this.Server.EndsWith("/") ? this.Server : this.Server + "/" +
"{0}/{1}";
var resp = Request(RequestType.Put,null,url,this.RepositoryKey, this.DirectoryName.EndsWith("/") ? this.DirectoryName : this.DirectoryName + "/");
if (HttpStatusCode.Created != resp.StatusCode)
{
LogError("Error creating Artifactory directory {0} in repository {1}. Error code is {2}", this.DirectoryName, this.RepositoryKey, resp.StatusCode);
return null;
}
return "OK";
}
}
}