This document illustrates building of the REST API which is able to identify a change made to the repo and respectively run the make command
This class contains a function which does the cloning of the github reposirtory, if repository already exists it pulls the latest changes
class RepoClone:
def __init__(self,git_url):
self.git_url = git_url
def repoCloner(self): #clone_repo before
(repo_name, repo_author) = repoNameExtacter(self.git_url)
ret_val = isRepoExist(repo_name)
if not ret_val:
command = "git clone %s; cd %s;git checkout %s;git pull" % (self.git_url, repo_name, GIT_BRANCH)
current_app.logger.debug("Git clone command : %s" % (command))
(ret_code, output) = linuxCommandExecuter(command)
if ret_code == 0:
current_app.logger.debug("Successfully cloned repo : %s" % (self.git_url))
return True
else:
current_app.logger.debug("repository already present, pulling repo : %s" % (self.git_url))
command = "cd %s; git checkout %s;git pull" % (repo_name, GIT_BRANCH)
(ret_code, output) = linuxCommandExecuter(command)
if ret_code == 0:
current_app.logger.debug("Successfully pulls the repository : %s" % (self.git_url))
return True
else:
current_app.logger.debug("Failed to pulls the repository : %s" % (self.git_url))
return False
class TestClone(unittest.TestCase):
TESTING = True
def create_app(self):
app = create_app(config)
return app
def setUp(self):
pass
def tearDown(self):
pass
def test_CiClone(self):
app = self.create_app()
with app.app_context():
print "test_ci_clone"
url = "https://github.com/vlead/lab-data-service"
rc = RepoClone(url)
print rc.repoCloner()
self.assertEqual(rc.repoCloner(), True)
- This Class contains the function which does the building the
sources of github repository and if its is failed to generate
build it creates the issue on respective git repository and
assigns label called
build_failed
. - If build is generated successfully it creates the issue on github
repository and assigns label called
build_passed
and closes the issue.
class RepoBuild:
def __init__(self, git_url):
self.git_url = git_url
'''This function is used to run the make commmand'''
def repoBuilder(self, git_url):#build_repo before
current_app.logger.debug("Running make command")
(repo_name, repo_author) = repoNameExtacter(self.git_url)
mk_cmd = 'cd %s;make' % (repo_name)
(ret_code, output) = linuxCommandExecuter(mk_cmd)
if ret_code == 0:
current_app.logger.debug("build generated successfully")
current_app.logger.debug("Creating github issue")
ret_status = makeGithubIssue(repo_author, repo_name, 'Build ran successfully', \
'Build ran successfully and docs are moved to doc server', \
'assigned_user', 3, ['build_passed'])
if ret_status:
current_app.logger.debug("Created github issue")
return True
else:
current_app.logger.debug("Failed to create github issue")
return True
else:
current_app.logger.debug("Couldn't generate build")
current_app.logger.debug("Creating github issue")
ret_status = makeGithubIssue(repo_author, repo_name, 'Failed to run build', \
'Failed to run build', 'assigned_user', 3, ['build_failed'])
if ret_status:
current_app.logger.debug("Created github issue")
return False
class TestBuild(unittest.TestCase):
def create_app(self):
app = create_app(config)
return app
def setUp(self):
pass
def tearDown(self):
pass
def testCiBuild(self):
app = self.create_app()
with app.app_context():
print "test_ci_build"
url = "https://github.com/vlead/lab-data-service"
rc = RepoClone(url)
rb = RepoBuild(url)
self.assertEqual(rb.repoBuilder(url), True)
This function executes the linux command and returns the output status code
def linuxCommandExecuter(cmd):
current_app.logger.debug("command: %s" % cmd)
return_code = -1 #If the linux command executes successfully it returns zero
output = None
try:
output = subprocess.check_output(cmd, shell=True)
return_code = 0
except subprocess.CalledProcessError as cpe:
current_app.logger.error("Called Process Error Message: %s" % cpe.output)
raise cpe
except OSError as ose:
current_app.logger.error("OSError: %s" % ose.output)
raise ose
return (return_code, output)
class TesteExecuteCommand(unittest.TestCase):
def create_app(self):
app = create_app(config)
return app
def setUp(self):
pass
def tearDown(self):
pass
def test_linuxCommandExecuter(self):
print "test_ci_build"
app = self.create_app()
with app.app_context():
url = "https://github.com/vlead/lab-data-service.git"
(ret_code, output) = linuxCommandExecuter("ls")
self.assertEqual(ret_code, 0)
This function extracts the repository name and its associated organization name for a given github repository url.
def repoNameExtacter(repo_url):
try:
repo_data = repo_url.split("/")
repo_name = repo_data[-1]
org_name = repo_data[-2]
current_app.logger.debug("repo_name %s, author_name = %s" % (repo_name, org_name))
return (repo_name, org_name)
except Exception as e:
current_app.logger.error("Exception %s" % (str(e)))
raise str(e)
class TesteExtractRepo(unittest.TestCase):
def create_app(self):
app = create_app(config)
return app
def setUp(self):
pass
def tearDown(self):
pass
def test_extract_repo(self):
print "test_ci_build"
print "test_ci_build"
app = self.create_app()
with app.app_context():
url = "https://github.com/vlead/lab-data-service"
(repo_name, repo_org) = repoNameExtacter(url)
self.assertEqual(repo_name, "lab-data-service")
self.assertEqual(repo_org, "vlead")
This function creates the github issue & assigns the label to it for a given repository. This function is useful to notify the project’s collabarators in terms of what are commits to a repository causes test suit failed/success.
def makeGithubIssue(repo_org, repo_name, title, body=None, assignee=None, milestone=None, labels=None):
git_api_url = '%s/%s/%s/issues' % (GIT_API, repo_org, repo_name)
current_app.logger.debug("Git REST API URL : %s" % (git_api_url))
if (repo_org != "vlead") or (repo_org != "virtual-labs"):
current_app.logger.error("Git repo = %s, organization = %s are not authorized to invoke web hook" % (repo_name, repo_org))
abort(401, "Unauthorized repository/organization")
try:
session = requests.Session()
session.auth = (USERNAME, PASSWORD)
issue = {'title': title,
'body': body,
'assignee': '',
'milestone': None,
'labels': labels
}
current_app.logger.debug("Creating issue on git repository = %s under organization = %s" % (repo_name, repo_org))
r = session.post(git_api_url, json.dumps(issue))
if r.status_code == 201:
current_app.logger.debug("Successfully created Issue : %s on repository = %s" % (title, repo_name))
return True
else:
current_app.logger.error("Could not creat Issue : %s on repository = %s" % (title, repo_name))
current_app.logger.error("Response : %s" % r.content)
return False
except Exception as e:
current_app.logger.error("Exception : %s" % str(e))
raise str(e)
class TesteCreateGitIssue(unittest.TestCase):
def create_app(self):
app = create_app(config)
return app
def setUp(self):
pass
def tearDown(self):
pass
def test_create_git_issue(self):
print "test_create_issue"
app = self.create_app()
with app.app_context():
url = "https://github.com/ksripathi/Documents"
(repo_name, repo_org) = repoNameExtacter(url)
title = "test issue"
ret_status = makeGithubIssue(repo_org, repo_name, title, body=None, assignee=None, milestone=None, labels=None)
self.assertEqual(ret_status, True)
This utility function does the pushing the literate documentation of a lab/service to a document server (Hosted on stagin environment)
def docsPusher(repo_name):
SRC_DIR = ("%s/build/docs/" % (repo_name))
try:
copy_command = "rsync -arz --progress " + SRC_DIR + " " + IP_ADDRESS + ":" + DEST_DIR + "/" + repo_name
current_app.logger.debug("copy command = %s" % copy_command)
(ret_code, output) = linuxCommandExecuter(copy_command)
if ret_code == 0:
current_app.logger.debug("Copied SRC_DIR = %s to DEST_DIR = %s/%s/%s" % (SRC_DIR, IP_ADDRESS, DEST_DIR, repo_name))
return True
else:
current_app.logger.debug("Copy Unsuccessful from SRC_DIR = %s to DEST_DIR = %s/%s/%s" % (SRC_DIR, IP_ADDRESS, DEST_DIR, repo_name))
current_app.logger.debug("Command = %s , return code = %s" % (copy_command, str(ret_code)))
return False
except Exception, e:
current_app.logger.error("ERROR = %s" % str(e))
return False
class TestePushDocs(unittest.TestCase):
def create_app(self):
app = create_app(config)
return app
def setUp(self):
pass
def tearDown(self):
pass
def test_extract_repo(self):
print "test_ci_build"
print "test_ci_build"
app = self.create_app()
with app.app_context():
url = "https://github.com/vlead/lab-data-service"
(repo_name, repo_org) = repoNameExtacter(url)
self.assertEqual(repo_name, "lab-data-service")
self.assertEqual(repo_org, "vlead")
This function checks for repository exist or not
def isRepoExist(repo_name):
current_app.logger.debug("Checking repo %s existance" % (repo_name))
try:
ret_val = os.path.exists(repo_name)
if ret_val:
current_app.logger.debug("Repository = %s arleady exists" % (repo_name))
return ret_val
else:
current_app.logger.debug("Repository = %s not exists" % (repo_name))
return ret_val
except subprocess.CalledProcessError as cpe:
current_app.logger.error("Called Process Error Message: %s" % cpe.output)
raise cpe
except OSError as ose:
current_app.logger.error("OSError: %s" % ose.output)
raise ose
class TesteRepoExist(unittest.TestCase):
def create_app(self):
app = create_app(config)
return app
def setUp(self):
pass
def tearDown(self):
pass
def test_repo_exist(self):
print "test_ci_build"
app = self.create_app()
with app.app_context():
url = "https://github.com/vlead/lab-data-service"
rc = RepoClone(url)
rc.repoCloner()
(repo_name, repo_org) = repoNameExtacter(url)
self.assertEqual(isRepoExist(repo_name), True)
- URL
- /ci_push_docs
- Method
- POST
- URL Params
- None
- Payload
{ "zen": "Responsive is better than fast.", "hook_id": 14493403, "hook": { "type": "Repository", "id": 14493403, "name": "web", "active": true, "events": [ "push" ], "config": { "content_type": "json", "insecure_ssl": "0", "url": "http://ci.vlabs.ac.in:5000/git" }, "updated_at": "2017-06-21T09:35:07Z", "created_at": "2017-06-21T09:35:07Z", "url": "https://api.github.com/repos/ksripathi/lab-data-service/hooks/14493403", "test_url": "https://api.github.com/repos/ksripathi/lab-data-service/hooks/14493403/test", "ping_url": "https://api.github.com/repos/ksripathi/lab-data-service/hooks/14493403/pings", "last_response": { "code": null, "status": "unused", "message": null } }, "repository": { "id": 93591178, "name": "lab-data-service", "full_name": "ksripathi/lab-data-service", "owner": { "login": "ksripathi", "id": 8774380, "avatar_url": "https://avatars3.githubusercontent.com/u/8774380?v=3", "gravatar_id": "", "url": "https://api.github.com/users/ksripathi", "html_url": "https://github.com/ksripathi", "followers_url": "https://api.github.com/users/ksripathi/followers", "following_url": "https://api.github.com/users/ksripathi/following{/other_user}", "gists_url": "https://api.github.com/users/ksripathi/gists{/gist_id}", "starred_url": "https://api.github.com/users/ksripathi/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ksripathi/subscriptions", "organizations_url": "https://api.github.com/users/ksripathi/orgs", "repos_url": "https://api.github.com/users/ksripathi/repos", "events_url": "https://api.github.com/users/ksripathi/events{/privacy}", "received_events_url": "https://api.github.com/users/ksripathi/received_events", "type": "User", "site_admin": false }, "private": false, "html_url": "https://github.com/ksripathi/lab-data-service", "description": null, "fork": true, "url": "https://api.github.com/repos/ksripathi/lab-data-service", "forks_url": "https://api.github.com/repos/ksripathi/lab-data-service/forks", "keys_url": "https://api.github.com/repos/ksripathi/lab-data-service/keys{/key_id}", "collaborators_url": "https://api.github.com/repos/ksripathi/lab-data-service/collaborators{/collaborator}", "teams_url": "https://api.github.com/repos/ksripathi/lab-data-service/teams", "hooks_url": "https://api.github.com/repos/ksripathi/lab-data-service/hooks", "issue_events_url": "https://api.github.com/repos/ksripathi/lab-data-service/issues/events{/number}", "events_url": "https://api.github.com/repos/ksripathi/lab-data-service/events", "assignees_url": "https://api.github.com/repos/ksripathi/lab-data-service/assignees{/user}", "branches_url": "https://api.github.com/repos/ksripathi/lab-data-service/branches{/branch}", "tags_url": "https://api.github.com/repos/ksripathi/lab-data-service/tags", "blobs_url": "https://api.github.com/repos/ksripathi/lab-data-service/git/blobs{/sha}", "git_tags_url": "https://api.github.com/repos/ksripathi/lab-data-service/git/tags{/sha}", "git_refs_url": "https://api.github.com/repos/ksripathi/lab-data-service/git/refs{/sha}", "trees_url": "https://api.github.com/repos/ksripathi/lab-data-service/git/trees{/sha}", "statuses_url": "https://api.github.com/repos/ksripathi/lab-data-service/statuses/{sha}", "languages_url": "https://api.github.com/repos/ksripathi/lab-data-service/languages", "stargazers_url": "https://api.github.com/repos/ksripathi/lab-data-service/stargazers", "contributors_url": "https://api.github.com/repos/ksripathi/lab-data-service/contributors", "subscribers_url": "https://api.github.com/repos/ksripathi/lab-data-service/subscribers", "subscription_url": "https://api.github.com/repos/ksripathi/lab-data-service/subscription", "commits_url": "https://api.github.com/repos/ksripathi/lab-data-service/commits{/sha}", "git_commits_url": "https://api.github.com/repos/ksripathi/lab-data-service/git/commits{/sha}", "comments_url": "https://api.github.com/repos/ksripathi/lab-data-service/comments{/number}", "issue_comment_url": "https://api.github.com/repos/ksripathi/lab-data-service/issues/comments{/number}", "contents_url": "https://api.github.com/repos/ksripathi/lab-data-service/contents/{+path}", "compare_url": "https://api.github.com/repos/ksripathi/lab-data-service/compare/{base}...{head}", "merges_url": "https://api.github.com/repos/ksripathi/lab-data-service/merges", "archive_url": "https://api.github.com/repos/ksripathi/lab-data-service/{archive_format}{/ref}", "downloads_url": "https://api.github.com/repos/ksripathi/lab-data-service/downloads", "issues_url": "https://api.github.com/repos/ksripathi/lab-data-service/issues{/number}", "pulls_url": "https://api.github.com/repos/ksripathi/lab-data-service/pulls{/number}", "milestones_url": "https://api.github.com/repos/ksripathi/lab-data-service/milestones{/number}", "notifications_url": "https://api.github.com/repos/ksripathi/lab-data-service/notifications{?since,all,participating}", "labels_url": "https://api.github.com/repos/ksripathi/lab-data-service/labels{/name}", "releases_url": "https://api.github.com/repos/ksripathi/lab-data-service/releases{/id}", "deployments_url": "https://api.github.com/repos/ksripathi/lab-data-service/deployments", "created_at": "2017-06-07T04:04:59Z", "updated_at": "2017-06-07T04:05:00Z", "pushed_at": "2017-06-08T11:11:07Z", "git_url": "git://github.com/ksripathi/lab-data-service.git", "ssh_url": "git@github.com:ksripathi/lab-data-service.git", "clone_url": "https://github.com/ksripathi/lab-data-service.git", "svn_url": "https://github.com/ksripathi/lab-data-service", "homepage": null, "size": 8979, "stargazers_count": 0, "watchers_count": 0, "language": "Shell", "has_issues": false, "has_projects": true, "has_downloads": true, "has_wiki": true, "has_pages": false, "forks_count": 0, "mirror_url": null, "open_issues_count": 0, "forks": 0, "open_issues": 0, "watchers": 0, "default_branch": "master" }, "sender": { "login": "ksripathi", "id": 8774380, "avatar_url": "https://avatars3.githubusercontent.com/u/8774380?v=3", "gravatar_id": "", "url": "https://api.github.com/users/ksripathi", "html_url": "https://github.com/ksripathi", "followers_url": "https://api.github.com/users/ksripathi/followers", "following_url": "https://api.github.com/users/ksripathi/following{/other_user}", "gists_url": "https://api.github.com/users/ksripathi/gists{/gist_id}", "starred_url": "https://api.github.com/users/ksripathi/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ksripathi/subscriptions", "organizations_url": "https://api.github.com/users/ksripathi/orgs", "repos_url": "https://api.github.com/users/ksripathi/repos", "events_url": "https://api.github.com/users/ksripathi/events{/privacy}", "received_events_url": "https://api.github.com/users/ksripathi/received_events", "type": "User", "site_admin": false } }
- Success Response
- Status_Code: 200
- Contents :
- Status_Code: 200
{ "status_code" : 200, "message" : "Successfully copied docs to server" }
- Error Response:
- Contents : {“status” : “error”}
- Example:
http://localhost:5000/ci_hook
@api.route("/ci_push_docs", methods = ['POST', 'GET'])
def ci_push_docs():
if request.method == "GET":
return "Method not allowed"
elif request.method == 'POST':
repo_data = request.get_json()
git_url = repo_data['repository']['html_url']
current_app.logger.debug("Git repository URL : %s" % (git_url))
else:
return "Method not allowed"
repo = RepoClone(git_url)
cmd_status = repo.repoCloner()
if cmd_status == True:
(repo_name, repo_author) = repoNameExtacter(git_url)
rtb = RepoBuild(git_url)
status = rtb.repoBuilder(git_url)
if status == True:
status = docsPusher(repo_name)
if status == True:
current_app.logger.debug("Successfully copied the docs to doc server")
message = {
"status_code" : 200,
"message" : "Successfully copied docs to server"
}
return jsonify(message)
else:
message = {
"status" : 500,
"message" : "Unable to copy files to docs server"
}
current_app.logger.error("Message %s" % (message))
return jsonify(message)
else:
message = {
"status" : 500,
"message" : "Failed to run make file"
}
current_app.logger.error("Message %s" % (message))
return jsonify(message)
else:
message = {
"status" : 500,
"message" : "Failed to clone repo"
}
current_app.logger.error("Message %s" % (message))
return jsonify(message)
class TestWebHook(TestCase):
TESTING = True
def create_app(self):
app = create_app(config)
return app
def setUp(self):
pass
def tearDown(self):
pass
def test_ci_web_hook(self):
print "test_ci_web_hook"
headers = {'Content-Type': 'application/json'}
payload = {
"zen": "Responsive is better than fast.",
"hook_id": 14493403,
"hook": {
"type": "Repository",
"id": 14493403,
"name": "web",
"active": "true",
"events": [
"push"
],
"config": {
"content_type": "json",
"insecure_ssl": "0",
"url": "http://ci.vlabs.ac.in:5000/git"
},
"updated_at": "2017-06-21T09:35:07Z",
"created_at": "2017-06-21T09:35:07Z",
"url": "https://api.github.com/repos/ksripathi/lab-data-service/hooks/14493403",
"test_url": "https://api.github.com/repos/ksripathi/lab-data-service/hooks/14493403/test",
"ping_url": "https://api.github.com/repos/ksripathi/lab-data-service/hooks/14493403/pings",
"last_response": {
"code": "null",
"status": "unused",
"message": "null"
}
},
"repository": {
"id": 93591178,
"name": "lab-data-service",
"full_name": "ksripathi/lab-data-service",
"owner": {
"login": "ksripathi",
"id": 8774380,
"avatar_url": "https://avatars3.githubusercontent.com/u/8774380?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/ksripathi",
"html_url": "https://github.com/ksripathi",
"followers_url": "https://api.github.com/users/ksripathi/followers",
"following_url": "https://api.github.com/users/ksripathi/following{/other_user}",
"gists_url": "https://api.github.com/users/ksripathi/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ksripathi/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ksripathi/subscriptions",
"organizations_url": "https://api.github.com/users/ksripathi/orgs",
"repos_url": "https://api.github.com/users/ksripathi/repos",
"events_url": "https://api.github.com/users/ksripathi/events{/privacy}",
"received_events_url": "https://api.github.com/users/ksripathi/received_events",
"type": "User",
"site_admin": "false"
},
"private": "false",
"html_url": "https://github.com/ksripathi/lab-data-service",
"description": "null",
"fork": "true",
"url": "https://api.github.com/repos/ksripathi/lab-data-service",
"forks_url": "https://api.github.com/repos/ksripathi/lab-data-service/forks",
"keys_url": "https://api.github.com/repos/ksripathi/lab-data-service/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/ksripathi/lab-data-service/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/ksripathi/lab-data-service/teams",
"hooks_url": "https://api.github.com/repos/ksripathi/lab-data-service/hooks",
"issue_events_url": "https://api.github.com/repos/ksripathi/lab-data-service/issues/events{/number}",
"events_url": "https://api.github.com/repos/ksripathi/lab-data-service/events",
"assignees_url": "https://api.github.com/repos/ksripathi/lab-data-service/assignees{/user}",
"branches_url": "https://api.github.com/repos/ksripathi/lab-data-service/branches{/branch}",
"tags_url": "https://api.github.com/repos/ksripathi/lab-data-service/tags",
"blobs_url": "https://api.github.com/repos/ksripathi/lab-data-service/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/ksripathi/lab-data-service/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/ksripathi/lab-data-service/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/ksripathi/lab-data-service/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/ksripathi/lab-data-service/statuses/{sha}",
"languages_url": "https://api.github.com/repos/ksripathi/lab-data-service/languages",
"stargazers_url": "https://api.github.com/repos/ksripathi/lab-data-service/stargazers",
"contributors_url": "https://api.github.com/repos/ksripathi/lab-data-service/contributors",
"subscribers_url": "https://api.github.com/repos/ksripathi/lab-data-service/subscribers",
"subscription_url": "https://api.github.com/repos/ksripathi/lab-data-service/subscription",
"commits_url": "https://api.github.com/repos/ksripathi/lab-data-service/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/ksripathi/lab-data-service/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/ksripathi/lab-data-service/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/ksripathi/lab-data-service/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/ksripathi/lab-data-service/contents/{+path}",
"compare_url": "https://api.github.com/repos/ksripathi/lab-data-service/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/ksripathi/lab-data-service/merges",
"archive_url": "https://api.github.com/repos/ksripathi/lab-data-service/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/ksripathi/lab-data-service/downloads",
"issues_url": "https://api.github.com/repos/ksripathi/lab-data-service/issues{/number}",
"pulls_url": "https://api.github.com/repos/ksripathi/lab-data-service/pulls{/number}",
"milestones_url": "https://api.github.com/repos/ksripathi/lab-data-service/milestones{/number}",
"notifications_url": "https://api.github.com/repos/ksripathi/lab-data-service/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/ksripathi/lab-data-service/labels{/name}",
"releases_url": "https://api.github.com/repos/ksripathi/lab-data-service/releases{/id}",
"deployments_url": "https://api.github.com/repos/ksripathi/lab-data-service/deployments",
"created_at": "2017-06-07T04:04:59Z",
"updated_at": "2017-06-07T04:05:00Z",
"pushed_at": "2017-06-08T11:11:07Z",
"git_url": "git://github.com/ksripathi/lab-data-service.git",
"ssh_url": "git@github.com:ksripathi/lab-data-service.git",
"clone_url": "https://github.com/ksripathi/lab-data-service.git",
"svn_url": "https://github.com/ksripathi/lab-data-service",
"homepage": "null",
"size": 8979,
"stargazers_count": 0,
"watchers_count": 0,
"language": "Shell",
"has_issues": "false",
"has_projects": "true",
"has_downloads": "true",
"has_wiki": "true",
"has_pages": "false",
"forks_count": 0,
"mirror_url": "null",
"open_issues_count": 0,
"forks": 0,
"open_issues": 0,
"watchers": 0,
"default_branch": "master"
},
"sender": {
"login": "ksripathi",
"id": 8774380,
"avatar_url": "https://avatars3.githubusercontent.com/u/8774380?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/ksripathi",
"html_url": "https://github.com/ksripathi",
"followers_url": "https://api.github.com/users/ksripathi/followers",
"following_url": "https://api.github.com/users/ksripathi/following{/other_user}",
"gists_url": "https://api.github.com/users/ksripathi/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ksripathi/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ksripathi/subscriptions",
"organizations_url": "https://api.github.com/users/ksripathi/orgs",
"repos_url": "https://api.github.com/users/ksripathi/repos",
"events_url": "https://api.github.com/users/ksripathi/events{/privacy}",
"received_events_url": "https://api.github.com/users/ksripathi/received_events",
"type": "User",
"site_admin": "false"
}
}
response = self.client.post("/ci_push_docs", data=json.dumps(payload),
headers=headers)
self.assertEqual(response.status_code, 200)
- URL
- /ci_build_sources
- Method
- POST
- URL Params
- None
- Payload
{ "zen": "Responsive is better than fast.", "hook_id": 14493403, "hook": { "type": "Repository", "id": 14493403, "name": "web", "active": true, "events": [ "push" ], "config": { "content_type": "json", "insecure_ssl": "0", "url": "http://ci.vlabs.ac.in:5000/git" }, "updated_at": "2017-06-21T09:35:07Z", "created_at": "2017-06-21T09:35:07Z", "url": "https://api.github.com/repos/ksripathi/lab-data-service/hooks/14493403", "test_url": "https://api.github.com/repos/ksripathi/lab-data-service/hooks/14493403/test", "ping_url": "https://api.github.com/repos/ksripathi/lab-data-service/hooks/14493403/pings", "last_response": { "code": null, "status": "unused", "message": null } }, "repository": { "id": 93591178, "name": "lab-data-service", "full_name": "ksripathi/lab-data-service", "owner": { "login": "ksripathi", "id": 8774380, "avatar_url": "https://avatars3.githubusercontent.com/u/8774380?v=3", "gravatar_id": "", "url": "https://api.github.com/users/ksripathi", "html_url": "https://github.com/ksripathi", "followers_url": "https://api.github.com/users/ksripathi/followers", "following_url": "https://api.github.com/users/ksripathi/following{/other_user}", "gists_url": "https://api.github.com/users/ksripathi/gists{/gist_id}", "starred_url": "https://api.github.com/users/ksripathi/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ksripathi/subscriptions", "organizations_url": "https://api.github.com/users/ksripathi/orgs", "repos_url": "https://api.github.com/users/ksripathi/repos", "events_url": "https://api.github.com/users/ksripathi/events{/privacy}", "received_events_url": "https://api.github.com/users/ksripathi/received_events", "type": "User", "site_admin": false }, "private": false, "html_url": "https://github.com/ksripathi/lab-data-service", "description": null, "fork": true, "url": "https://api.github.com/repos/ksripathi/lab-data-service", "forks_url": "https://api.github.com/repos/ksripathi/lab-data-service/forks", "keys_url": "https://api.github.com/repos/ksripathi/lab-data-service/keys{/key_id}", "collaborators_url": "https://api.github.com/repos/ksripathi/lab-data-service/collaborators{/collaborator}", "teams_url": "https://api.github.com/repos/ksripathi/lab-data-service/teams", "hooks_url": "https://api.github.com/repos/ksripathi/lab-data-service/hooks", "issue_events_url": "https://api.github.com/repos/ksripathi/lab-data-service/issues/events{/number}", "events_url": "https://api.github.com/repos/ksripathi/lab-data-service/events", "assignees_url": "https://api.github.com/repos/ksripathi/lab-data-service/assignees{/user}", "branches_url": "https://api.github.com/repos/ksripathi/lab-data-service/branches{/branch}", "tags_url": "https://api.github.com/repos/ksripathi/lab-data-service/tags", "blobs_url": "https://api.github.com/repos/ksripathi/lab-data-service/git/blobs{/sha}", "git_tags_url": "https://api.github.com/repos/ksripathi/lab-data-service/git/tags{/sha}", "git_refs_url": "https://api.github.com/repos/ksripathi/lab-data-service/git/refs{/sha}", "trees_url": "https://api.github.com/repos/ksripathi/lab-data-service/git/trees{/sha}", "statuses_url": "https://api.github.com/repos/ksripathi/lab-data-service/statuses/{sha}", "languages_url": "https://api.github.com/repos/ksripathi/lab-data-service/languages", "stargazers_url": "https://api.github.com/repos/ksripathi/lab-data-service/stargazers", "contributors_url": "https://api.github.com/repos/ksripathi/lab-data-service/contributors", "subscribers_url": "https://api.github.com/repos/ksripathi/lab-data-service/subscribers", "subscription_url": "https://api.github.com/repos/ksripathi/lab-data-service/subscription", "commits_url": "https://api.github.com/repos/ksripathi/lab-data-service/commits{/sha}", "git_commits_url": "https://api.github.com/repos/ksripathi/lab-data-service/git/commits{/sha}", "comments_url": "https://api.github.com/repos/ksripathi/lab-data-service/comments{/number}", "issue_comment_url": "https://api.github.com/repos/ksripathi/lab-data-service/issues/comments{/number}", "contents_url": "https://api.github.com/repos/ksripathi/lab-data-service/contents/{+path}", "compare_url": "https://api.github.com/repos/ksripathi/lab-data-service/compare/{base}...{head}", "merges_url": "https://api.github.com/repos/ksripathi/lab-data-service/merges", "archive_url": "https://api.github.com/repos/ksripathi/lab-data-service/{archive_format}{/ref}", "downloads_url": "https://api.github.com/repos/ksripathi/lab-data-service/downloads", "issues_url": "https://api.github.com/repos/ksripathi/lab-data-service/issues{/number}", "pulls_url": "https://api.github.com/repos/ksripathi/lab-data-service/pulls{/number}", "milestones_url": "https://api.github.com/repos/ksripathi/lab-data-service/milestones{/number}", "notifications_url": "https://api.github.com/repos/ksripathi/lab-data-service/notifications{?since,all,participating}", "labels_url": "https://api.github.com/repos/ksripathi/lab-data-service/labels{/name}", "releases_url": "https://api.github.com/repos/ksripathi/lab-data-service/releases{/id}", "deployments_url": "https://api.github.com/repos/ksripathi/lab-data-service/deployments", "created_at": "2017-06-07T04:04:59Z", "updated_at": "2017-06-07T04:05:00Z", "pushed_at": "2017-06-08T11:11:07Z", "git_url": "git://github.com/ksripathi/lab-data-service.git", "ssh_url": "git@github.com:ksripathi/lab-data-service.git", "clone_url": "https://github.com/ksripathi/lab-data-service.git", "svn_url": "https://github.com/ksripathi/lab-data-service", "homepage": null, "size": 8979, "stargazers_count": 0, "watchers_count": 0, "language": "Shell", "has_issues": false, "has_projects": true, "has_downloads": true, "has_wiki": true, "has_pages": false, "forks_count": 0, "mirror_url": null, "open_issues_count": 0, "forks": 0, "open_issues": 0, "watchers": 0, "default_branch": "master" }, "sender": { "login": "ksripathi", "id": 8774380, "avatar_url": "https://avatars3.githubusercontent.com/u/8774380?v=3", "gravatar_id": "", "url": "https://api.github.com/users/ksripathi", "html_url": "https://github.com/ksripathi", "followers_url": "https://api.github.com/users/ksripathi/followers", "following_url": "https://api.github.com/users/ksripathi/following{/other_user}", "gists_url": "https://api.github.com/users/ksripathi/gists{/gist_id}", "starred_url": "https://api.github.com/users/ksripathi/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ksripathi/subscriptions", "organizations_url": "https://api.github.com/users/ksripathi/orgs", "repos_url": "https://api.github.com/users/ksripathi/repos", "events_url": "https://api.github.com/users/ksripathi/events{/privacy}", "received_events_url": "https://api.github.com/users/ksripathi/received_events", "type": "User", "site_admin": false } }
- Success Response
- Status_Code: 200
- Contents :
- Status_Code: 200
{ "status_code" : 200, "message" : "Successfully build the sources" }
- Error Response:
- Contents : {“status” : “error”}
- Example:
http://localhost:5000/ci_build_sources
@api.route("/ci_build_sources", methods = ['POST', 'GET'])
def build_repo():
if request.method == "GET":
return "Method not allowed"
elif request.method == 'POST':
repo_data = request.get_json()
git_url = repo_data['repository']['html_url']
current_app.logger.debug("Git repository URL : %s" % (git_url))
else:
return "Method not allowed"
repo = RepoClone(git_url)
cmd_status = repo.repoCloner()
if cmd_status == True:
(repo_name, repo_author) = repoNameExtacter(git_url)
rtb = RepoBuild(git_url)
status = rtb.repoBuilder(git_url)
if status == True:
message = {
"status" : 200,
"message" : "Successfully build the sources"
}
current_app.logger.debug("Message %s" % (message))
return jsonify(message)
else:
message = {
"status" : 500,
"message" : "Failed to run make file"
}
current_app.logger.error("Message %s" % (message))
return jsonify(message)
else:
message = {
"status" : 500,
"message" : "Failed to clone repo"
}
current_app.logger.error("Message %s" % (message))
return jsonify(message)
class TestBuilSources(TestCase):
TESTING = True
def create_app(self):
app = create_app(config)
return app
def setUp(self):
pass
def tearDown(self):
pass
def test_ci_build_sources(self):
print "test_ci_build_sources"
headers = {'Content-Type': 'application/json'}
payload = {
"zen": "Responsive is better than fast.",
"hook_id": 14493403,
"hook": {
"type": "Repository",
"id": 14493403,
"name": "web",
"active": "true",
"events": [
"push"
],
"config": {
"content_type": "json",
"insecure_ssl": "0",
"url": "http://ci.vlabs.ac.in:5000/git"
},
"updated_at": "2017-06-21T09:35:07Z",
"created_at": "2017-06-21T09:35:07Z",
"url": "https://api.github.com/repos/ksripathi/lab-data-service/hooks/14493403",
"test_url": "https://api.github.com/repos/ksripathi/lab-data-service/hooks/14493403/test",
"ping_url": "https://api.github.com/repos/ksripathi/lab-data-service/hooks/14493403/pings",
"last_response": {
"code": "null",
"status": "unused",
"message": "null"
}
},
"repository": {
"id": 93591178,
"name": "lab-data-service",
"full_name": "ksripathi/lab-data-service",
"owner": {
"login": "ksripathi",
"id": 8774380,
"avatar_url": "https://avatars3.githubusercontent.com/u/8774380?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/ksripathi",
"html_url": "https://github.com/ksripathi",
"followers_url": "https://api.github.com/users/ksripathi/followers",
"following_url": "https://api.github.com/users/ksripathi/following{/other_user}",
"gists_url": "https://api.github.com/users/ksripathi/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ksripathi/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ksripathi/subscriptions",
"organizations_url": "https://api.github.com/users/ksripathi/orgs",
"repos_url": "https://api.github.com/users/ksripathi/repos",
"events_url": "https://api.github.com/users/ksripathi/events{/privacy}",
"received_events_url": "https://api.github.com/users/ksripathi/received_events",
"type": "User",
"site_admin": "false"
},
"private": "false",
"html_url": "https://github.com/ksripathi/lab-data-service",
"description": "null",
"fork": "true",
"url": "https://api.github.com/repos/ksripathi/lab-data-service",
"forks_url": "https://api.github.com/repos/ksripathi/lab-data-service/forks",
"keys_url": "https://api.github.com/repos/ksripathi/lab-data-service/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/ksripathi/lab-data-service/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/ksripathi/lab-data-service/teams",
"hooks_url": "https://api.github.com/repos/ksripathi/lab-data-service/hooks",
"issue_events_url": "https://api.github.com/repos/ksripathi/lab-data-service/issues/events{/number}",
"events_url": "https://api.github.com/repos/ksripathi/lab-data-service/events",
"assignees_url": "https://api.github.com/repos/ksripathi/lab-data-service/assignees{/user}",
"branches_url": "https://api.github.com/repos/ksripathi/lab-data-service/branches{/branch}",
"tags_url": "https://api.github.com/repos/ksripathi/lab-data-service/tags",
"blobs_url": "https://api.github.com/repos/ksripathi/lab-data-service/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/ksripathi/lab-data-service/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/ksripathi/lab-data-service/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/ksripathi/lab-data-service/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/ksripathi/lab-data-service/statuses/{sha}",
"languages_url": "https://api.github.com/repos/ksripathi/lab-data-service/languages",
"stargazers_url": "https://api.github.com/repos/ksripathi/lab-data-service/stargazers",
"contributors_url": "https://api.github.com/repos/ksripathi/lab-data-service/contributors",
"subscribers_url": "https://api.github.com/repos/ksripathi/lab-data-service/subscribers",
"subscription_url": "https://api.github.com/repos/ksripathi/lab-data-service/subscription",
"commits_url": "https://api.github.com/repos/ksripathi/lab-data-service/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/ksripathi/lab-data-service/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/ksripathi/lab-data-service/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/ksripathi/lab-data-service/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/ksripathi/lab-data-service/contents/{+path}",
"compare_url": "https://api.github.com/repos/ksripathi/lab-data-service/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/ksripathi/lab-data-service/merges",
"archive_url": "https://api.github.com/repos/ksripathi/lab-data-service/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/ksripathi/lab-data-service/downloads",
"issues_url": "https://api.github.com/repos/ksripathi/lab-data-service/issues{/number}",
"pulls_url": "https://api.github.com/repos/ksripathi/lab-data-service/pulls{/number}",
"milestones_url": "https://api.github.com/repos/ksripathi/lab-data-service/milestones{/number}",
"notifications_url": "https://api.github.com/repos/ksripathi/lab-data-service/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/ksripathi/lab-data-service/labels{/name}",
"releases_url": "https://api.github.com/repos/ksripathi/lab-data-service/releases{/id}",
"deployments_url": "https://api.github.com/repos/ksripathi/lab-data-service/deployments",
"created_at": "2017-06-07T04:04:59Z",
"updated_at": "2017-06-07T04:05:00Z",
"pushed_at": "2017-06-08T11:11:07Z",
"git_url": "git://github.com/ksripathi/lab-data-service.git",
"ssh_url": "git@github.com:ksripathi/lab-data-service.git",
"clone_url": "https://github.com/ksripathi/lab-data-service.git",
"svn_url": "https://github.com/ksripathi/lab-data-service",
"homepage": "null",
"size": 8979,
"stargazers_count": 0,
"watchers_count": 0,
"language": "Shell",
"has_issues": "false",
"has_projects": "true",
"has_downloads": "true",
"has_wiki": "true",
"has_pages": "false",
"forks_count": 0,
"mirror_url": "null",
"open_issues_count": 0,
"forks": 0,
"open_issues": 0,
"watchers": 0,
"default_branch": "master"
},
"sender": {
"login": "ksripathi",
"id": 8774380,
"avatar_url": "https://avatars3.githubusercontent.com/u/8774380?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/ksripathi",
"html_url": "https://github.com/ksripathi",
"followers_url": "https://api.github.com/users/ksripathi/followers",
"following_url": "https://api.github.com/users/ksripathi/following{/other_user}",
"gists_url": "https://api.github.com/users/ksripathi/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ksripathi/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ksripathi/subscriptions",
"organizations_url": "https://api.github.com/users/ksripathi/orgs",
"repos_url": "https://api.github.com/users/ksripathi/repos",
"events_url": "https://api.github.com/users/ksripathi/events{/privacy}",
"received_events_url": "https://api.github.com/users/ksripathi/received_events",
"type": "User",
"site_admin": "false"
}
}
response = self.client.post("/build_sources", data=json.dumps(payload),
headers=headers)
self.assertEqual(response.status_code, 200)
- URL
- /ci_deploy_repo
- Method
- POST
- URL Params
- None
- Payload
{ "zen": "Responsive is better than fast.", "hook_id": 14493403, "hook": { "type": "Repository", "id": 14493403, "name": "web", "active": true, "events": [ "push" ], "config": { "content_type": "json", "insecure_ssl": "0", "url": "http://ci.vlabs.ac.in:5000/git" }, "updated_at": "2017-06-21T09:35:07Z", "created_at": "2017-06-21T09:35:07Z", "url": "https://api.github.com/repos/ksripathi/lab-data-service/hooks/14493403", "test_url": "https://api.github.com/repos/ksripathi/lab-data-service/hooks/14493403/test", "ping_url": "https://api.github.com/repos/ksripathi/lab-data-service/hooks/14493403/pings", "last_response": { "code": null, "status": "unused", "message": null } }, "repository": { "id": 93591178, "name": "lab-data-service", "full_name": "ksripathi/lab-data-service", "owner": { "login": "ksripathi", "id": 8774380, "avatar_url": "https://avatars3.githubusercontent.com/u/8774380?v=3", "gravatar_id": "", "url": "https://api.github.com/users/ksripathi", "html_url": "https://github.com/ksripathi", "followers_url": "https://api.github.com/users/ksripathi/followers", "following_url": "https://api.github.com/users/ksripathi/following{/other_user}", "gists_url": "https://api.github.com/users/ksripathi/gists{/gist_id}", "starred_url": "https://api.github.com/users/ksripathi/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ksripathi/subscriptions", "organizations_url": "https://api.github.com/users/ksripathi/orgs", "repos_url": "https://api.github.com/users/ksripathi/repos", "events_url": "https://api.github.com/users/ksripathi/events{/privacy}", "received_events_url": "https://api.github.com/users/ksripathi/received_events", "type": "User", "site_admin": false }, "private": false, "html_url": "https://github.com/ksripathi/lab-data-service", "description": null, "fork": true, "url": "https://api.github.com/repos/ksripathi/lab-data-service", "forks_url": "https://api.github.com/repos/ksripathi/lab-data-service/forks", "keys_url": "https://api.github.com/repos/ksripathi/lab-data-service/keys{/key_id}", "collaborators_url": "https://api.github.com/repos/ksripathi/lab-data-service/collaborators{/collaborator}", "teams_url": "https://api.github.com/repos/ksripathi/lab-data-service/teams", "hooks_url": "https://api.github.com/repos/ksripathi/lab-data-service/hooks", "issue_events_url": "https://api.github.com/repos/ksripathi/lab-data-service/issues/events{/number}", "events_url": "https://api.github.com/repos/ksripathi/lab-data-service/events", "assignees_url": "https://api.github.com/repos/ksripathi/lab-data-service/assignees{/user}", "branches_url": "https://api.github.com/repos/ksripathi/lab-data-service/branches{/branch}", "tags_url": "https://api.github.com/repos/ksripathi/lab-data-service/tags", "blobs_url": "https://api.github.com/repos/ksripathi/lab-data-service/git/blobs{/sha}", "git_tags_url": "https://api.github.com/repos/ksripathi/lab-data-service/git/tags{/sha}", "git_refs_url": "https://api.github.com/repos/ksripathi/lab-data-service/git/refs{/sha}", "trees_url": "https://api.github.com/repos/ksripathi/lab-data-service/git/trees{/sha}", "statuses_url": "https://api.github.com/repos/ksripathi/lab-data-service/statuses/{sha}", "languages_url": "https://api.github.com/repos/ksripathi/lab-data-service/languages", "stargazers_url": "https://api.github.com/repos/ksripathi/lab-data-service/stargazers", "contributors_url": "https://api.github.com/repos/ksripathi/lab-data-service/contributors", "subscribers_url": "https://api.github.com/repos/ksripathi/lab-data-service/subscribers", "subscription_url": "https://api.github.com/repos/ksripathi/lab-data-service/subscription", "commits_url": "https://api.github.com/repos/ksripathi/lab-data-service/commits{/sha}", "git_commits_url": "https://api.github.com/repos/ksripathi/lab-data-service/git/commits{/sha}", "comments_url": "https://api.github.com/repos/ksripathi/lab-data-service/comments{/number}", "issue_comment_url": "https://api.github.com/repos/ksripathi/lab-data-service/issues/comments{/number}", "contents_url": "https://api.github.com/repos/ksripathi/lab-data-service/contents/{+path}", "compare_url": "https://api.github.com/repos/ksripathi/lab-data-service/compare/{base}...{head}", "merges_url": "https://api.github.com/repos/ksripathi/lab-data-service/merges", "archive_url": "https://api.github.com/repos/ksripathi/lab-data-service/{archive_format}{/ref}", "downloads_url": "https://api.github.com/repos/ksripathi/lab-data-service/downloads", "issues_url": "https://api.github.com/repos/ksripathi/lab-data-service/issues{/number}", "pulls_url": "https://api.github.com/repos/ksripathi/lab-data-service/pulls{/number}", "milestones_url": "https://api.github.com/repos/ksripathi/lab-data-service/milestones{/number}", "notifications_url": "https://api.github.com/repos/ksripathi/lab-data-service/notifications{?since,all,participating}", "labels_url": "https://api.github.com/repos/ksripathi/lab-data-service/labels{/name}", "releases_url": "https://api.github.com/repos/ksripathi/lab-data-service/releases{/id}", "deployments_url": "https://api.github.com/repos/ksripathi/lab-data-service/deployments", "created_at": "2017-06-07T04:04:59Z", "updated_at": "2017-06-07T04:05:00Z", "pushed_at": "2017-06-08T11:11:07Z", "git_url": "git://github.com/ksripathi/lab-data-service.git", "ssh_url": "git@github.com:ksripathi/lab-data-service.git", "clone_url": "https://github.com/ksripathi/lab-data-service.git", "svn_url": "https://github.com/ksripathi/lab-data-service", "homepage": null, "size": 8979, "stargazers_count": 0, "watchers_count": 0, "language": "Shell", "has_issues": false, "has_projects": true, "has_downloads": true, "has_wiki": true, "has_pages": false, "forks_count": 0, "mirror_url": null, "open_issues_count": 0, "forks": 0, "open_issues": 0, "watchers": 0, "default_branch": "master" }, "sender": { "login": "ksripathi", "id": 8774380, "avatar_url": "https://avatars3.githubusercontent.com/u/8774380?v=3", "gravatar_id": "", "url": "https://api.github.com/users/ksripathi", "html_url": "https://github.com/ksripathi", "followers_url": "https://api.github.com/users/ksripathi/followers", "following_url": "https://api.github.com/users/ksripathi/following{/other_user}", "gists_url": "https://api.github.com/users/ksripathi/gists{/gist_id}", "starred_url": "https://api.github.com/users/ksripathi/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ksripathi/subscriptions", "organizations_url": "https://api.github.com/users/ksripathi/orgs", "repos_url": "https://api.github.com/users/ksripathi/repos", "events_url": "https://api.github.com/users/ksripathi/events{/privacy}", "received_events_url": "https://api.github.com/users/ksripathi/received_events", "type": "User", "site_admin": false } }
- Success Response
- Status_Code: 200
- Contents :
- Status_Code: 200
{ "status_code" : 200, "message" : "Successfully deployed repository", "ip" : "127.0.0.1" }
- Error Response:
- Contents : {“status” : “error”}
- Example:
http://localhost:5000/ci_deploy_lab
@api.route("/ci_deploy_repo", methods = ['POST', 'GET'])
def deploy_repo():
if request.method == "GET":
return "Method not allowed"
elif request.method == 'POST':
repo_data = request.get_json()
git_url = repo_data['repository']['html_url']
current_app.logger.debug("Git repository URL : %s" % (git_url))
else:
return "Method not allowed"
repo = RepoClone(git_url)
cmd_status = repo.repoCloner()
if cmd_status == True:
(repo_name, repo_author) = repoNameExtacter(git_url)
rtb = RepoBuild(git_url)
status = rtb.repoBuilder(git_url)
if status == True:
lab_id = repo_name
lab_url = git_url
tag = GIT_BRANCH
if tag == "":
tag = "master"
data = {'lab_id': lab_id, 'lab_src_url': lab_url, 'version': tag, \
'key' : ADS_SECRET_KEY, "current_user" : session.get('current_user')}
current_app.logger.debug("lab_id = %s, lab_src_url=%s, "
"version=%s, key=%s, "
%(lab_id, lab_url, tag, ADS_SECRET_KEY))
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
try:
r = requests.post(ADS_URL, data=json.dumps(data), headers=headers)
if r.status_code == 200:
if r.text == "Test failed: See log file for errors":
return "Error"
else:
data['url'] = "http://" + r.text
return jsonify(data)
elif r.status_code == 401:
current_app.logger.error("error code = %s" % str(r.status_code))
return "Unauthorized credentials"
else:
return "Error"
except Exception as e:
current_app.logger.error("error code = %s" % str(e))
raise str(e)
else:
message = {
"status" : 500,
"message" : "Failed to run make file"
}
current_app.logger.error("Message %s" % (message))
return jsonify(message)
else:
message = {
"status" : 500,
"message" : "Failed to clone repo"
}
current_app.logger.error("Message %s" % (message))
return jsonify(message)
class TestDeployRepo(TestCase):
TESTING = True
def create_app(self):
app = create_app(config)
return app
def setUp(self):
pass
def tearDown(self):
pass
def test_ci_build_sources(self):
print "test_ci_build_sources"
headers = {'Content-Type': 'application/json'}
payload = {
"zen": "Responsive is better than fast.",
"hook_id": 14493403,
"hook": {
"type": "Repository",
"id": 14493403,
"name": "web",
"active": "true",
"events": [
"push"
],
"config": {
"content_type": "json",
"insecure_ssl": "0",
"url": "http://ci.vlabs.ac.in:5000/git"
},
"updated_at": "2017-06-21T09:35:07Z",
"created_at": "2017-06-21T09:35:07Z",
"url": "https://api.github.com/repos/ksripathi/lab-data-service/hooks/14493403",
"test_url": "https://api.github.com/repos/ksripathi/lab-data-service/hooks/14493403/test",
"ping_url": "https://api.github.com/repos/ksripathi/lab-data-service/hooks/14493403/pings",
"last_response": {
"code": "null",
"status": "unused",
"message": "null"
}
},
"repository": {
"id": 93591178,
"name": "lab-data-service",
"full_name": "ksripathi/lab-data-service",
"owner": {
"login": "ksripathi",
"id": 8774380,
"avatar_url": "https://avatars3.githubusercontent.com/u/8774380?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/ksripathi",
"html_url": "https://github.com/ksripathi",
"followers_url": "https://api.github.com/users/ksripathi/followers",
"following_url": "https://api.github.com/users/ksripathi/following{/other_user}",
"gists_url": "https://api.github.com/users/ksripathi/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ksripathi/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ksripathi/subscriptions",
"organizations_url": "https://api.github.com/users/ksripathi/orgs",
"repos_url": "https://api.github.com/users/ksripathi/repos",
"events_url": "https://api.github.com/users/ksripathi/events{/privacy}",
"received_events_url": "https://api.github.com/users/ksripathi/received_events",
"type": "User",
"site_admin": "false"
},
"private": "false",
"html_url": "https://github.com/ksripathi/lab-data-service",
"description": "null",
"fork": "true",
"url": "https://api.github.com/repos/ksripathi/lab-data-service",
"forks_url": "https://api.github.com/repos/ksripathi/lab-data-service/forks",
"keys_url": "https://api.github.com/repos/ksripathi/lab-data-service/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/ksripathi/lab-data-service/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/ksripathi/lab-data-service/teams",
"hooks_url": "https://api.github.com/repos/ksripathi/lab-data-service/hooks",
"issue_events_url": "https://api.github.com/repos/ksripathi/lab-data-service/issues/events{/number}",
"events_url": "https://api.github.com/repos/ksripathi/lab-data-service/events",
"assignees_url": "https://api.github.com/repos/ksripathi/lab-data-service/assignees{/user}",
"branches_url": "https://api.github.com/repos/ksripathi/lab-data-service/branches{/branch}",
"tags_url": "https://api.github.com/repos/ksripathi/lab-data-service/tags",
"blobs_url": "https://api.github.com/repos/ksripathi/lab-data-service/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/ksripathi/lab-data-service/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/ksripathi/lab-data-service/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/ksripathi/lab-data-service/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/ksripathi/lab-data-service/statuses/{sha}",
"languages_url": "https://api.github.com/repos/ksripathi/lab-data-service/languages",
"stargazers_url": "https://api.github.com/repos/ksripathi/lab-data-service/stargazers",
"contributors_url": "https://api.github.com/repos/ksripathi/lab-data-service/contributors",
"subscribers_url": "https://api.github.com/repos/ksripathi/lab-data-service/subscribers",
"subscription_url": "https://api.github.com/repos/ksripathi/lab-data-service/subscription",
"commits_url": "https://api.github.com/repos/ksripathi/lab-data-service/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/ksripathi/lab-data-service/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/ksripathi/lab-data-service/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/ksripathi/lab-data-service/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/ksripathi/lab-data-service/contents/{+path}",
"compare_url": "https://api.github.com/repos/ksripathi/lab-data-service/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/ksripathi/lab-data-service/merges",
"archive_url": "https://api.github.com/repos/ksripathi/lab-data-service/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/ksripathi/lab-data-service/downloads",
"issues_url": "https://api.github.com/repos/ksripathi/lab-data-service/issues{/number}",
"pulls_url": "https://api.github.com/repos/ksripathi/lab-data-service/pulls{/number}",
"milestones_url": "https://api.github.com/repos/ksripathi/lab-data-service/milestones{/number}",
"notifications_url": "https://api.github.com/repos/ksripathi/lab-data-service/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/ksripathi/lab-data-service/labels{/name}",
"releases_url": "https://api.github.com/repos/ksripathi/lab-data-service/releases{/id}",
"deployments_url": "https://api.github.com/repos/ksripathi/lab-data-service/deployments",
"created_at": "2017-06-07T04:04:59Z",
"updated_at": "2017-06-07T04:05:00Z",
"pushed_at": "2017-06-08T11:11:07Z",
"git_url": "git://github.com/ksripathi/lab-data-service.git",
"ssh_url": "git@github.com:ksripathi/lab-data-service.git",
"clone_url": "https://github.com/ksripathi/lab-data-service.git",
"svn_url": "https://github.com/ksripathi/lab-data-service",
"homepage": "null",
"size": 8979,
"stargazers_count": 0,
"watchers_count": 0,
"language": "Shell",
"has_issues": "false",
"has_projects": "true",
"has_downloads": "true",
"has_wiki": "true",
"has_pages": "false",
"forks_count": 0,
"mirror_url": "null",
"open_issues_count": 0,
"forks": 0,
"open_issues": 0,
"watchers": 0,
"default_branch": "master"
},
"sender": {
"login": "ksripathi",
"id": 8774380,
"avatar_url": "https://avatars3.githubusercontent.com/u/8774380?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/ksripathi",
"html_url": "https://github.com/ksripathi",
"followers_url": "https://api.github.com/users/ksripathi/followers",
"following_url": "https://api.github.com/users/ksripathi/following{/other_user}",
"gists_url": "https://api.github.com/users/ksripathi/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ksripathi/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ksripathi/subscriptions",
"organizations_url": "https://api.github.com/users/ksripathi/orgs",
"repos_url": "https://api.github.com/users/ksripathi/repos",
"events_url": "https://api.github.com/users/ksripathi/events{/privacy}",
"received_events_url": "https://api.github.com/users/ksripathi/received_events",
"type": "User",
"site_admin": "false"
}
}
response = self.client.post("/ci_deploy_repo", data=json.dumps(payload),
headers=headers)
self.assertEqual(response.status_code, 200)
# -*- coding: utf-8 -*-
import requests
import json
import subprocess
from runtime.config.git_config import USERNAME, PASSWORD, IP_ADDRESS, DEST_DIR, GIT_API, GIT_BRANCH
from flask import session, render_template, Blueprint, request, \
jsonify, abort, current_app, redirect, url_for
from flask import Flask
import yaml
api = Blueprint('APIs', __name__)
import os
# -*- coding: utf-8 -*-
import unittest
from flask_testing import TestCase
from runtime.rest.app import create_app
from runtime.rest.api import *
import datetime
config = {
'SQLALCHEMY_DATABASE_URI': ''
}
if __name__ == '__main__':
unittest.main()
<<imports_for_sources>>
<<build_repo>>
<<clone_repo>>
<<exec_commands>>
<<repo_exist>>
<<get_repo_name>>
<<create_issue>>
<<push_docs>>
<<ci_hook>>
<<ci_deploy_repo>>
<<ci_push_docs>>
<<imports_for_tests>>
#<<test_clone_repo>>
#<<test_build_repo>>
#<<test_exec_cmd>>
#<<test_push_docs>>
<<test_create_issue>>
#<<test_extract_repo>>
#<<test_repo_exist>>
#<<test_ci_push_docs>>
#<<test_build_sources>>
#<<test_ci_deploy_repo>>
<<run_test_cases>>