Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
scripts
mahara-scripts
Commits
775d831e
Commit
775d831e
authored
Jul 18, 2018
by
Robert Lyon
Browse files
Merge branch 'master' of
https://git.mahara.org/scripts/mahara-scripts
parents
75a74909
77a8c5d6
Changes
1
Show whitespace changes
Inline
Side-by-side
tools/gerrit_query.php
0 → 100644
View file @
775d831e
<?php
/**
* Using php to do the json_decode / checking of patch status
* as it is easier than trying to get bash to do it
*
* to call this file via bash do something like:
*
* outcome=`php gerrit_query.php -- $patchnum ref`
* if [ "$outcome" != "0" ]; then
* git fetch https://reviews.mahara.org/mahara $outcome && git checkout FETCH_HEAD
* fi
*
* where $patchnum = id of gerrit patch, eg 1234
* It should return the related ref path
*/
$gerrit_patch_number
=
$argv
[
2
];
$gerrit_field
=
$argv
[
3
];
$ch
=
curl_init
();
curl_setopt
(
$ch
,
CURLOPT_URL
,
'https://reviews.mahara.org/changes/?q='
.
$gerrit_patch_number
.
'&o=LABELS&o=CURRENT_REVISION&o=CURRENT_COMMIT&pp=0'
);
curl_setopt
(
$ch
,
CURLOPT_RETURNTRANSFER
,
1
);
$content
=
curl_exec
(
$ch
);
curl_close
(
$ch
);
// We need to fetch the json line from the result
$content
=
explode
(
"
\n
"
,
$content
);
$content
=
json_decode
(
$content
[
1
]);
// Now check to see if anyone has rejected this
if
(
!
empty
(
$content
[
0
]))
{
// Doublecheck to see if this has already been merged
if
(
$content
[
0
]
->
status
==
'MERGED'
)
{
echo
0
;
exit
;
}
if
(
empty
(
$content
[
0
]
->
current_revision
))
{
echo
0
;
exit
;
}
if
(
!
empty
(
$gerrit_field
))
{
$info
=
''
;
switch
(
$gerrit_field
)
{
case
'ref'
:
$info
=
$content
[
0
]
->
revisions
->
{
$content
[
0
]
->
current_revision
}
->
ref
;
break
;
default
:
$info
=
0
;
}
echo
$info
;
exit
;
}
echo
0
;
}
else
{
echo
0
;
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment