Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cubicweb
cube-doctor
Commits
65ac0d5ac78b
Commit
6f3e33e4
authored
Apr 17, 2021
by
Laurent Peuch
Browse files
feat: template for proposing a base .cube-doctor.yml config
parent
8fc3d9b10eea
Changes
2
Hide whitespace changes
Inline
Side-by-side
cube_doctor/doctor_hg.py
View file @
65ac0d5a
...
...
@@ -8,7 +8,9 @@ from cube_doctor import (
get_all_projects_am_member_of
,
)
from
cube_doctor.utils
import
COMMANDS
,
commands_to_run
from
cube_doctor.transforms.propose_base_config
import
ProposeBaseConfig
propose_base_config
=
ProposeBaseConfig
().
workflow
def
hg_command
(
dir
,
command
):
# look for inspiration at
...
...
@@ -21,10 +23,16 @@ def auto_mr(delay):
config
=
parse_config
(
project
)
if
config
is
None
:
logger
.
info
(
f
"project '
{
project
.
id
}
{
project
.
name
}
' doesn't have .cube-doctor.yml, skip"
)
logger
.
info
(
f
"project '
{
project
.
id
}
{
project
.
name
}
' doesn't have .cube-doctor.yml, skip"
)
propose_base_config
(
apply
=
True
,
project
=
project
,
interactif
=
False
,
merge_when_pipeline_succeeds
=
True
,
)
continue
# TODO
# propose_base_config(project)
for
command
,
arguments
in
commands_to_run
(
config
):
# checks?
...
...
cube_doctor/transforms/propose_base_config.py
0 → 100644
View file @
65ac0d5a
import
logging
from
ruamel.yaml
import
YAML
from
cube_doctor
import
Command
logger
=
logging
.
getLogger
(
"cube_doctor"
)
MR_MESSAGE
=
"""
\
Hello dear contributors,
CubeDoctor has been given access to this repository, but to know how to works
this repository needs to have a `.cube-doctor.yml` file in its root directory.
This MR is a proposition of a base `.cube-doctor.yml` for your project.
If you want CubeDoctor to work on your project accept (and if wanted modify
`.cube-doctor.yml`)
If you don't want `.cube-doctor.yml` to work on your project, refuse this MR.
If you later change your mind, add a `.cube-doctor.yml` yourself.
You can find the whole documentation and the signification of each lines of
this config file here: https://forge.extranet.logilab.fr/cubicweb/cube-doctor
Kind regards,
"""
# this is a special command that will probably never be called explicitly but will be invoke by
# auto-mr if the project doesn't already have a .cube-doctor.yml
class
ProposeBaseConfig
(
Command
):
command_name
=
"propose-base-config"
BRANCH_NAME
=
"topic/default/add-cube-doctor-yml"
commit_message
=
"chore(cube-doctor): add cube-doctor.yml"
TARGETS
=
(
"cubes"
,
"core"
,
"client"
)
mr_message
=
MR_MESSAGE
def
pre_check
(
self
,
root_files
):
if
".cube-doctor.yml"
in
root_files
:
return
"continue"
def
modify_code
(
self
,
cube
,
repo
,
root_files
,
branches
,
other_args
):
# circular imports
from
cube_doctor.utils
import
COMMANDS
# noqa
# we ignore unused cubes
if
(
cube
.
namespace
[
"full_path"
]
==
"cubicweb/cubes"
and
"project-dependency"
in
cube
.
tag_list
):
project_kind
=
"cubes"
project_kind_template
=
"cubicweb-cube"
elif
"cw-core"
in
cube
.
tag_list
:
project_kind
=
"core"
project_kind_template
=
"cubicweb-core"
elif
"client-project"
in
cube
.
tag_list
:
project_kind
=
"clients"
project_kind_template
=
"cubicweb-app"
elif
"logilab-project"
in
cube
.
tag_list
:
project_kind
=
"clients"
project_kind_template
=
"cubicweb-app"
elif
[
x
for
x
in
root_files
if
x
.
startswith
(
"cubicweb_"
)]:
...
# XXX
return
else
:
logger
.
info
(
f
"couldn't determine the type of project that '
{
cube
.
id
}
{
cube
.
name
}
' is, don't "
"propose a .cube-doctor.yml"
)
return
yaml
=
YAML
(
typ
=
"safe"
)
yaml
.
default_flow_style
=
False
cube_doctor_yml
=
{
"rules"
:
{
command_name
:
{}
for
command_name
,
command
in
sorted
(
COMMANDS
.
items
(),
key
=
lambda
x
:
x
[
0
]
)
if
project_kind
in
command
.
TARGETS
}
}
cube_doctor_yml
[
"rules"
][
"add-new-rules"
]
=
{
"project-kind"
:
project_kind_template
}
yaml
.
dump
(
cube_doctor_yml
,
repo
.
path
/
".cube-doctor.yml"
)
repo
.
run_command
(
"hg add .cube-doctor.yml"
)
if
"MANIFEST.in"
in
root_files
:
manifest_content
=
repo
.
read_file
(
"MANIFEST.in"
)
manifest_content
=
(
manifest_content
.
rstrip
()
+
"
\n
exclude .cube-doctor.yml
\n
"
)
repo
.
write_file
(
"MANIFEST.in"
,
manifest_content
)
logger
.
info
(
f
"would have propose base config '
{
project_kind
}
' for project '
{
cube
.
id
}
{
cube
.
name
}
'"
)
yield
{
"branch_name"
:
self
.
BRANCH_NAME
,
"commit_message"
:
self
.
commit_message
}
Write
Preview
Markdown
is supported
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