-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathproject_src_github.module
More file actions
116 lines (99 loc) · 3.46 KB
/
Copy pathproject_src_github.module
File metadata and controls
116 lines (99 loc) · 3.46 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
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
<?php
/**
* @file
* Project Source: GitHub module hooks and functions.
*/
/**
* Includes private/helpers file. Functions contained here should not be used
* by any other module.
*/
require_once(dirname(__FILE__) . '/includes/project_src_github.private.inc');
/**
* Implements hook_menu().
*/
function project_src_github_menu() {
// Admin callback.
$items['admin/config/development/project-src/github'] = array(
'title' => 'Project Source: GitHub',
'description' => 'Configure GitHub API options for the Project Source module.',
'type' => MENU_LOCAL_TASK,
'page callback' => 'drupal_get_form',
'page arguments' => array('project_src_github_settings'),
'access arguments' => array('administer project github src'),
'file' => 'includes/project_src_github.admin.inc',
);
// Callback to download archive packages in the correct format.
$public_stream_wrapper = new DrupalPublicStreamWrapper();
$public_files = $public_stream_wrapper->getDirectoryPath();
$base = count(explode('/', $public_files));
$items[$public_files . '/project-src-github/%/%/%/download.tar.gz'] = array(
'title' => 'File download callback for a specific project release',
'delivery callback' => 'project_src_deliver_clean_page',
'page callback' => 'project_src_github_get_archive',
'page arguments' => array(++$base , ++$base, ++$base),
'access callback' => TRUE,
'file' => 'includes/project_src_github.archive.inc',
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Implements hook_menu_alter().
*/
function project_src_github_menu_alter(&$items) {
// In the event the user is on an older version of Project Source, provide a
// default local task so our settings are easy to find.
$items['admin/config/development/project-src/settings'] = array(
'title' => 'Global settings',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
}
/**
* Implements hook_permission().
*/
function project_src_github_permission() {
return array(
'administer project github src' => array(
'title' => t('Administer Project Source: GitHub'),
'description' => t('Perform administration tasks for Project Source: GitHub'),
'restrict access' => TRUE,
),
);
}
/**
* Implements hook github_webhook_event().
*
* Clears Project Source: GitHub caches on commit to a tracked repository.
*/
function project_src_github_github_webhook_event($payload, &$response, $args) {
// Ensure that the payload corresponds to a project we manage.
if (isset($payload['repository']['name'])) {
foreach (project_src_get_projects(NULL, 'project_src_github') as $project) {
if (isset($project[$payload['repository']['name']])) {
project_src_github_clear_cache();
watchdog('project src gitlab', 'Project Source: GitHub cache cleared by commit to @repo.', array(
'@repo' => $payload['repository']['name'],
), WATCHDOG_NOTICE);
break;
}
}
}
}
/**
* Clears Project Source: GitHub's cached projects, releases and XML.
*/
function project_src_github_clear_cache() {
cache_clear_all('project_src_github', 'cache', TRUE);
cache_clear_all('%/drupal/release-history/', 'cache_page', TRUE);
}
/**
* Helper function to return a GitHub API paginator.
*
* @param GithubClient $client
* @return ResultPager
*/
function project_src_github_get_paginator($client) {
$paginatorClass = variable_get('project_src_github_paginator_class', 'Github\ResultPager');
return new $paginatorClass($client);
}