forked from tmate/tmate.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stash-rest-api.html
116 lines (76 loc) · 4.39 KB
/
stash-rest-api.html
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
---
layout: documentation
subtitle: SVN Mirror Add-On for Bitbucket Server REST API
---
<div class="wrapper">
{% capture content %}
SVN Mirror Add-On for Bitbucker Server provides number of REST API end points that could be used to control configured mirrors.
### <a name="sync"></a>1. How to use REST API to invoke SVN/Git sync
Major REST API use-case is explicit sync invocation for a particular mirror. By default, Git/SVN mirror polls SVN repository
every 60 seconds to fetch new changes if there are any. This works fine for most of the users of the add-on, but may lead
to performance issues when there are a lot of configured mirrors.
One of the ways to workaround this issue and significantly reduce server load is only to perform sync when there are new
revisions available in SVN repository. Periodic polling might be then disabled (by setting poll interval to 0) or configured
to use much longer interval, e.g. one of 3600 seconds (1 hour). When sync is explicitly invoked it is also has a benefit
of SVN changes being available in Git mostly immediately after SVN commit is completed.
The requirement for the explicit sync configuration is shell access to SVN repository - one will have to install special
post-commit hook script into SVN repository that will notify add-on of the new changes via REST API.
$ edit SVN_REPOS/hooks/post-commit
For add-on version 3.0.4 or newer or 3.2.4 or newer:
#!/bin/sh
REPOS="$1"
REV="$2"
BITBUCKET_HOST=192.168.9.10
BITBUCKET_PATH=stash
BITBUCKET_PORT=7990
SVN_REPOS_UUID=$(svnlook uuid "$REPOS")
SVN_CHANGED_PATHS=$(svnlook changed -r "$REV" "$REPOS" | awk 1 ORS='\\n')
curl -s -u username:password -H "Content-Type: application/json" -H "X-Atlassian-Token:no-check" -X POST -d "{ \"uuid\" : \"$SVN_REPOS_UUID\", \"revision\" : \"$REV\", \"changedPaths\" : \"$SVN_CHANGED_PATHS\" }" "http://$BITBUCKET_HOST:$BITBUCKET_PORT/$BITBUCKET_PATH/rest/svn/1.0/sync"
exit 0
For add-on version 3.0.3 or older or 3.2.3 or older:
#!/bin/sh
REPOS="$1"
REV="$2"
BITBUCKET_HOST=192.168.9.10
BITBUCKET_PATH=stash
BITBUCKET_PORT=7990
SVN_REPOS_UUID=$(svnlook uuid "$REPOS")
SVN_CHANGED_PATHS=$(svnlook changed -r "$REV" "$REPOS" | awk 1 ORS='\\n')
curl -s -u username:password -H "X-Atlassian-Token:no-check" -X POST "http://$BITBUCKET_HOST:$BITBUCKET_PORT/$BITBUCKET_PATH/rest/svn/1.0/svnUUID/$SVN_REPOS_UUID?command=sync"
exit 0
Make sure post-commit hook script is executable:
$ chmod ugo+x SVN_REPOS/hooks/post-commit
Upon receiving notification, add-on will invoke sync for mirrors that might be affected by the newly committed SVN revision.
To complete configuration, set "Poll interval" (Repository | Settings | Subversion Mirror | Connection Tab) to 3600 to enable occasional scheduled sync.
### 2. REST API end-points reference:
Invoke sync for all configured Git mirrors of SVN repositories with UUID:
Request: POST
URL: http://BITBUCKET_HOST/rest/svn/1.0/svnUUID/SVN_REPOS_UUID?command=sync
Body: none
Invoke sync for all configured Git mirrors of SVN repositories with specified UUID and paths:
URL: http://BITBUCKET_HOST/rest/svn/1.0/sync
Request: POST
Content-Type: application/json
Body: JSON object of a form:
{
"uuid" : "SVN_REPOS_UUID",
"revision" : "SVN_REVISION",
"changedPaths" : "paths modified in SVN_REVISION a format of 'svnlook changed' command' with newlines escaped"
}
Invoke sync for a particular mirror:
Request: POST
URL: http://BITBUCKET_HOST/rest/svn/1.0/projects/PROJECT_KEY/repos/REPO_SLUG?command=sync
Disalbe or enable sync for a particular mirror:
Request: POST
URL: http://BITBUCKET_HOST/rest/svn/1.0/projects/PROJECT_KEY/repos/REPO_SLUG?command=start|stop
Change mirror configuration option (only available in 3.2.x):
Request: POST
URL: http://BITBUCKET_HOST/rest/svn/1.0/projects/PROJECT_KEY/repos/REPO_SLUG/config?name=OPTION_NAME&value=OPTION_VALUE
Change global configuration option (only available in 3.2.x):
Request: POST
URL: http://BITBUCKET_HOST/rest/svn/1.0/config?name=OPTION_NAME&value=OPTION_VALUE
### 3. Get Support<a name="support"></a>
Would you have any question on using SubGit with Gerrit, don't hesitate to contact us at [support@subgit.com](mailto:support@subgit.com). We'd be glad to assist you.
{% endcapture %}
{{ content | markdownify }}
</div>