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
8e8323cb
Commit
8e8323cb
authored
Jan 27, 2019
by
xiphon
Browse files
implement FFS requests parsing and validating, MR assignment, state changes handling
parent
e125c0fa
Changes
2
Hide whitespace changes
Inline
Side-by-side
app/Console/Commands/ProcessProposals.php
View file @
8e8323cb
...
...
@@ -3,6 +3,8 @@
namespace
App\Console\Commands
;
use
App\Project
;
use
GitLab\Connection
;
use
GuzzleHttp\Client
;
use
Illuminate\Console\Command
;
use
Illuminate\Support\Facades\Storage
;
use
Yaml
;
...
...
@@ -33,33 +35,88 @@ class ProcessProposals extends Command
parent
::
__construct
();
}
private
function
getMergedMrFilenameToUrlMap
()
{
$result
=
[];
$connection
=
new
Connection
(
new
Client
());
$merged
=
$connection
->
mergeRequests
(
'merged'
);
foreach
(
$merged
as
$request
)
{
$newFiles
=
$connection
->
getNewFiles
(
$request
->
iid
);
if
(
sizeof
(
$newFiles
)
!=
1
)
{
continue
;
}
$filename
=
$newFiles
[
0
];
if
(
!
preg_match
(
'/.+\.md$/'
,
$filename
))
{
continue
;
}
if
(
basename
(
$filename
)
!=
$filename
)
{
continue
;
}
$result
[
$filename
]
=
$request
->
web_url
;
}
return
$result
;
}
private
const
layoutToState
=
[
'ffs-fr'
=>
'FUNDING-REQUIRED'
,
'ffs-wip'
=>
'WORK-IN-PROGRESS'
,
'ffs-cp'
=>
'COMPLETED'
];
/**
* Execute the console command.
*/
public
function
handle
()
{
$details
=
[];
$mergedMrFilenameToUrlMap
=
null
;
$files
=
Storage
::
files
(
'ffs-proposals'
);
foreach
(
$files
as
$file
)
{
if
(
strpos
(
$file
,
'.md'
))
{
$detail
[
'name'
]
=
$file
;
if
(
!
strpos
(
$file
,
'.md'
))
{
continue
;
}
$filename
=
basename
(
$file
);
try
{
$detail
[
'name'
]
=
$filename
;
$detail
[
'values'
]
=
$this
->
getAmountFromText
(
$file
);
$details
[]
=
$detail
[
'values'
][
'title'
];
$project
=
Project
::
where
(
'title'
,
$detail
[
'values'
][
'title'
])
->
first
();
if
(
$project
)
{
$project
->
filename
=
$file
;
if
(
$project
->
state
===
'IDEA'
)
{
$project
->
state
=
'FUNDING-REQUIRED'
;
$amount
=
floatval
(
str_replace
(
","
,
"."
,
$detail
[
'values'
][
'amount'
]));
$author
=
htmlspecialchars
(
$detail
[
'values'
][
'author'
],
ENT_QUOTES
);
$date
=
strtotime
(
$detail
[
'values'
][
'date'
]);
$state
=
$this
::
layoutToState
[
$detail
[
'values'
][
'layout'
]];
$title
=
htmlspecialchars
(
$detail
[
'values'
][
'title'
],
ENT_QUOTES
);
$project
=
Project
::
where
(
'filename'
,
$filename
)
->
first
();
if
(
!
$project
)
{
if
(
$mergedMrFilenameToUrlMap
===
null
)
{
$mergedMrFilenameToUrlMap
=
$this
->
getMergedMrFilenameToUrlMap
();
}
if
(
!
isset
(
$mergedMrFilenameToUrlMap
[
$filename
]))
{
$this
->
error
(
"Project
$filename
: failed to find matching merged MR"
);
$gitlab_url
=
null
;
}
else
{
$gitlab_url
=
htmlspecialchars
(
$mergedMrFilenameToUrlMap
[
$filename
],
ENT_QUOTES
);
}
$project
->
target_amount
=
$detail
[
'values'
][
'amount'
];
$project
->
save
();
$this
->
info
(
"New project
$filename
Gitlab MR '
$gitlab_url
'"
);
$project
=
new
Project
();
$project
->
gitlab_url
=
$gitlab_url
;
$project
->
created_at
=
$date
;
$project
->
filename
=
$filename
;
}
else
{
$this
->
info
(
"Updating project
$filename
"
);
}
$project
->
author
=
$author
;
$project
->
state
=
$state
;
$project
->
target_amount
=
$amount
;
$project
->
title
=
$title
;
$project
->
save
();
}
catch
(
\
Exception
$e
)
{
$this
->
error
(
"Error processing project
$filename
:
{
$e
->
getMessage
()
}
"
);
}
}
foreach
(
$details
as
$det
)
{
$this
->
line
(
$det
);
}
}
/**
...
...
database/migrations/2018_09_10_211623_create_projects_table.php
View file @
8e8323cb
...
...
@@ -21,11 +21,11 @@ class CreateProjectsTable extends Migration
$table
->
string
(
'address'
)
->
nullable
();
$table
->
string
(
'address_uri'
)
->
nullable
();
$table
->
string
(
'qr_code'
)
->
nullable
();
$table
->
string
(
'target_amount'
)
->
nullable
()
;
$table
->
string
(
'raised_amount'
)
->
nullable
(
);
$table
->
string
(
'state'
)
->
default
(
'OPENED'
)
;
$table
->
string
(
'filename'
)
->
nullabl
e
();
$table
->
string
(
'gitlab_url'
);
$table
->
float
(
'target_amount'
);
$table
->
float
(
'raised_amount'
)
->
default
(
0
);
$table
->
string
(
'state'
);
$table
->
string
(
'filename'
)
->
uniqu
e
();
$table
->
string
(
'gitlab_url'
)
->
nullable
()
;
$table
->
timestamps
();
});
}
...
...
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