Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
monero-project
CCS Backend
Commits
b9a9902e
Commit
b9a9902e
authored
Jan 27, 2019
by
xiphon
Browse files
fetch Ideas on 'ffs:update' cmd from open Gitlab MR with single .md file
parent
d96509b7
Changes
4
Hide whitespace changes
Inline
Side-by-side
app/Console/Commands/FetchMergeRequests.php
deleted
100644 → 0
View file @
d96509b7
<?php
namespace
App\Console\Commands
;
use
App\Project
;
use
GitLab\Connection
;
use
GuzzleHttp\Client
;
use
Illuminate\Console\Command
;
class
fetchMergeRequests
extends
Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected
$signature
=
'gitlab:fetch-proposals'
;
/**
* The console command description.
*
* @var string
*/
protected
$description
=
'fetch all the proposal merge requests from gitlab'
;
/**
* Create a new command instance.
*
* @return void
*/
public
function
__construct
()
{
parent
::
__construct
();
}
/**
* Execute the console command.
*/
public
function
handle
()
{
$connection
=
new
Connection
(
new
Client
());
$projects
=
$connection
->
mergeRequests
(
'all'
);
foreach
(
$projects
as
$project
)
{
$state
=
'OPENED'
;
if
(
strpos
(
$project
->
title
,
'[IDEA]'
)
!==
false
)
{
$state
=
'IDEA'
;
}
$title
=
str_replace
(
'[IDEA]'
,
''
,
$project
->
title
);
// create requests that are still pending
$project
=
Project
::
firstOrNew
([
'merge_request_id'
=>
$project
->
id
,
],[
'state'
=>
$state
,
'title'
=>
trim
(
$title
),
'gitlab_state'
=>
$project
->
state
,
'gitlab_username'
=>
$project
->
author
->
username
,
'gitlab_url'
=>
$project
->
web_url
,
]);
$project
->
save
();
}
}
// fetch the idea
// check for merged merges.
// if proposal merged search for its md file
//issue payment_id and payment page
//
}
app/Console/Commands/UpdateSiteProposals.php
View file @
b9a9902e
...
...
@@ -4,6 +4,8 @@ namespace App\Console\Commands;
use
App\Project
;
use
Illuminate\Console\Command
;
use
GitLab\Connection
;
use
GuzzleHttp\Client
;
use
stdClass
;
use
Symfony\Component\Yaml\Yaml
;
...
...
@@ -52,15 +54,44 @@ class UpdateSiteProposals extends Command
$group
=
new
stdClass
();
$group
->
stage
=
'Ideas'
;
$responseProposals
=
[];
$proposals
=
Project
::
where
(
'gitlab_state'
,
'opened'
)
->
where
(
'state'
,
'IDEA'
)
->
get
();
foreach
(
$proposals
as
$proposal
)
{
$ideas
=
[];
$connection
=
new
Connection
(
new
Client
());
$mergeRequests
=
$connection
->
mergeRequests
(
'opened'
);
foreach
(
$mergeRequests
as
$mergeRequest
)
{
$newFiles
=
$connection
->
getNewFiles
(
$mergeRequest
->
iid
);
if
(
sizeof
(
$newFiles
)
!=
1
)
{
$this
->
error
(
"Skipping MR #
$mergeRequest->id
'
$mergeRequest->title
': contains multiple files"
);
continue
;
}
$filename
=
$newFiles
[
0
];
if
(
!
preg_match
(
'/.+\.md$/'
,
$filename
))
{
$this
->
error
(
"Skipping MR #
$mergeRequest->id
'
$mergeRequest->title
': doesn't contain any .md file"
);
continue
;
}
if
(
basename
(
$filename
)
!=
$filename
)
{
$this
->
error
(
"Skipping MR #
$mergeRequest->id
'
$mergeRequest->title
':
$filename
must be in the root folder"
);
continue
;
}
if
(
in_array
(
$filename
,
$ideas
))
{
$this
->
error
(
"Skipping MR #
$mergeRequest->id
'
$mergeRequest->title
': duplicated
$filename
, another MR #
$ideas[$filename]
->id"
);
continue
;
}
$project
=
Project
::
where
(
'filename'
,
$filename
)
->
first
();
if
(
$project
)
{
$this
->
error
(
"Skipping MR #
$mergeRequest->id
'
$mergeRequest->title
': already have a project
$filename
"
);
continue
;
}
$this
->
info
(
"Idea MR #
$mergeRequest->id
'
$mergeRequest->title
':
$filename
"
);
$prop
=
new
stdClass
();
$prop
->
name
=
$proposal
->
title
;
$prop
->
{
'gitlab-url'
}
=
$proposal
->
gitlab_url
;
$prop
->
author
=
$proposal
->
gitlab_username
;
$prop
->
date
=
$proposal
->
gitlab_created_at
->
format
(
'F j, Y'
);
$prop
->
name
=
htmlspecialchars
(
trim
(
$mergeRequest
->
title
),
ENT_QUOTES
)
;
$prop
->
{
'gitlab-url'
}
=
htmlspecialchars
(
$mergeRequest
->
web_url
,
ENT_QUOTES
)
;
$prop
->
author
=
htmlspecialchars
(
$mergeRequest
->
author
->
username
,
ENT_QUOTES
)
;
$prop
->
date
=
date
(
'F j, Y'
,
strtotime
(
$mergeRequest
->
created_at
)
);
$responseProposals
[]
=
$prop
;
}
$group
->
proposals
=
$responseProposals
;
return
$group
;
}
...
...
app/Console/Kernel.php
View file @
b9a9902e
...
...
@@ -2,7 +2,6 @@
namespace
App\Console
;
use
App\Console\Commands\fetchMergeRequests
;
use
App\Console\Commands\GenerateAddresses
;
use
App\Console\Commands\ProcessProposals
;
use
App\Console\Commands\UpdateSiteProposals
;
...
...
@@ -29,8 +28,6 @@ class Kernel extends ConsoleKernel
*/
protected
function
schedule
(
Schedule
$schedule
)
{
$schedule
->
command
(
fetchMergeRequests
::
class
)
->
everyMinute
();
$schedule
->
command
(
GenerateAddresses
::
class
)
->
everyMinute
();
$schedule
->
command
(
ProcessProposals
::
class
)
...
...
gitlab/Connection.php
View file @
b9a9902e
...
...
@@ -23,4 +23,20 @@ class Connection
return
collect
(
json_decode
(
$response
->
getBody
()));
}
public
function
getNewFiles
(
$merge_request_iid
)
{
$url
=
env
(
'GITLAB_URL'
)
.
'/merge_requests/'
.
$merge_request_iid
.
'/changes'
;
$response
=
$this
->
client
->
request
(
'GET'
,
$url
,
[
'headers'
=>
[
'Private-Token'
=>
env
(
'GITLAB_ACCESS_TOKEN'
)]]);
$deserialized
=
collect
(
json_decode
(
$response
->
getBody
()));
$result
=
[];
foreach
(
$deserialized
[
'changes'
]
as
$change
)
{
if
(
$change
->
new_file
)
{
$result
[]
=
$change
->
new_path
;
}
}
return
$result
;
}
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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