1
|
|
|
#!/usr/bin/env python |
2
|
|
|
|
3
|
|
|
# Licensed to the StackStorm, Inc ('StackStorm') under one or more |
4
|
|
|
# contributor license agreements. See the NOTICE file distributed with |
5
|
|
|
# this work for additional information regarding copyright ownership. |
6
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0 |
7
|
|
|
# (the "License"); you may not use this file except in compliance with |
8
|
|
|
# the License. You may obtain a copy of the License at |
9
|
|
|
# |
10
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
# |
12
|
|
|
# Unless required by applicable law or agreed to in writing, software |
13
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
# See the License for the specific language governing permissions and |
16
|
|
|
# limitations under the License. |
17
|
|
|
|
18
|
|
|
import sys |
19
|
|
|
import requests |
20
|
|
|
import json |
21
|
|
|
import getopt |
22
|
|
|
import argparse |
23
|
|
|
import os |
24
|
|
|
import yaml |
25
|
|
|
|
26
|
|
|
from getpass import getpass |
27
|
|
|
from st2actions.runners.pythonrunner import Action |
28
|
|
|
|
29
|
|
|
class CheckAutoDeployRepo(Action): |
30
|
|
|
def run(self, branch, repo_name): |
31
|
|
|
"""Returns the required data to complete an auto deployment of a pack in repo_name. |
32
|
|
|
|
33
|
|
|
The branch is expected to be in the format _refs/heads/foo_, if |
34
|
|
|
it's not then the comprassion will fail. |
35
|
|
|
|
36
|
|
|
Returns: A Dict with deployment_branch and notify_channel. |
37
|
|
|
|
38
|
|
|
Raises: |
39
|
|
|
ValueError: If the repo_name should not be auto deployed or |
40
|
|
|
config is not complete. |
41
|
|
|
""" |
42
|
|
|
results = {} |
43
|
|
|
|
44
|
|
|
try: |
45
|
|
|
results['deployment_branch'] = self.config["repositories"][repo_name]["auto_deployment"]["branch"] |
46
|
|
|
results['notify_channel'] = self.config["repositories"][repo_name]["auto_deployment"]["notify_channel"] |
47
|
|
|
except KeyError: |
48
|
|
|
raise ValueError("No repositories or auto_deployment config for '%s'" % repo_name) |
49
|
|
|
else: |
50
|
|
|
if branch == "refs/heads/%s" % results['deployment_branch']: |
51
|
|
|
return results |
52
|
|
|
else: |
53
|
|
|
raise ValueError("Branch %s for %s should not be auto deployed" % (branch, repo_name)) |
54
|
|
|
|