This repository was archived by the owner on Mar 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstart.php
More file actions
48 lines (38 loc) · 1.28 KB
/
Copy pathstart.php
File metadata and controls
48 lines (38 loc) · 1.28 KB
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
<?php
include 'init.php';
if (!isset($_GET['service']) || !isset($_GET['location']))
{
header('Status: 400 Bad Request');
die;
}
$repo = $_GET['location'];
if (!$repo_info = github_api("repos/$repo"))
{
die('The requested repo does not exist');
}
if ($repo_info['owner']['login'] != $_SESSION['github']['user_data']['login'])
{
die('Seems like you are not the owner of the requested repo.');
}
$branch_info = github_api("repos/$repo/branches/master");
if ($inserted_repo = db_insert_repo('github', $repo, strtolower($repo_info['language']), $branch_info['commit']['sha']))
{
//Create a job for the first docs
if (!db_insert_job($inserted_repo['id_repo'], $branch_info['commit']['sha']))
{
die('An error occurred when registrating a job for generating your docs :(');
}
//Declare the web hook so GitHub will notify every push in the repo
$resp = github_api("repos/$repo/hooks", array(
'name' => 'web',
'active' => true,
'events' => array('push'),
'config' => array(
'url' => GITHUB_HOOK_URL,
'content_type' => 'json',
'secret' => $inserted_repo['secret']
)
));
header('Location: index.php?notify_new=' . urlencode($repo));
}
die('An error occurred when registrating your new repo - sorry!');