Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
229c2efc
Commit
229c2efc
authored
Oct 10, 2019
by
mo khan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove unfavourable usage of classes
parent
1826e08f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
71 deletions
+67
-71
ee/app/assets/javascripts/vue_shared/license_management/mappers/v1.js
...s/javascripts/vue_shared/license_management/mappers/v1.js
+0
-7
ee/app/assets/javascripts/vue_shared/license_management/mappers/v2.js
...s/javascripts/vue_shared/license_management/mappers/v2.js
+0
-58
ee/app/assets/javascripts/vue_shared/license_management/report_mapper.js
...avascripts/vue_shared/license_management/report_mapper.js
+67
-6
No files found.
ee/app/assets/javascripts/vue_shared/license_management/mappers/v1.js
deleted
100644 → 0
View file @
1826e08f
/* eslint-disable class-methods-use-this */
export
default
class
{
mapFrom
(
report
)
{
return
report
;
}
}
ee/app/assets/javascripts/vue_shared/license_management/mappers/v2.js
deleted
100644 → 0
View file @
1826e08f
import
{
byLicenseNameComparator
}
from
'
../store/utils
'
;
export
default
class
V2
{
mapFrom
(
report
)
{
this
.
licenseMap
=
V2
.
createLicenseMap
(
report
.
licenses
);
this
.
licenses
=
report
.
licenses
.
sort
(
byLicenseNameComparator
).
map
(
V2
.
mapFromLicense
);
return
{
licenses
:
this
.
licenses
,
dependencies
:
report
.
dependencies
.
map
(
v2Dependency
=>
this
.
mapFromDependency
(
v2Dependency
)),
};
}
combine
(
licenses
)
{
return
licenses
.
reduce
(
(
memo
,
licenseId
)
=>
{
const
license
=
this
.
licenseMap
[
licenseId
];
this
.
incrementCountFor
(
license
.
name
);
if
(
memo
.
name
===
null
)
{
return
{
name
:
license
.
name
,
url
:
license
.
url
,
};
}
return
{
name
:
`
${
memo
.
name
}
,
${
license
.
name
}
`
,
url
:
''
};
},
{
name
:
null
,
url
:
null
},
);
}
incrementCountFor
(
licenseName
)
{
const
legacyLicense
=
this
.
licenses
.
find
(
license
=>
license
.
name
===
licenseName
);
if
(
legacyLicense
)
legacyLicense
.
count
+=
1
;
}
mapFromDependency
(
dependency
)
{
return
{
license
:
this
.
combine
(
dependency
.
licenses
),
dependency
:
{
name
:
dependency
.
name
,
url
:
dependency
.
url
,
description
:
dependency
.
description
,
},
};
}
static
mapFromLicense
(
license
)
{
return
{
name
:
license
.
name
,
count
:
0
};
}
static
createLicenseMap
(
licenses
)
{
return
licenses
.
reduce
((
memo
,
item
)
=>
{
memo
[
item
.
id
]
=
{
name
:
item
.
name
,
url
:
item
.
url
};
// eslint-disable-line no-param-reassign
return
memo
;
},
{});
}
}
ee/app/assets/javascripts/vue_shared/license_management/report_mapper.js
View file @
229c2efc
import
V1
from
'
./mappers/v1
'
;
import
V2
from
'
./mappers/v2
'
;
import
{
byLicenseNameComparator
}
from
'
./store/utils
'
;
class
V2ToV1Mapper
{
mapFrom
(
report
)
{
this
.
licenseMap
=
V2ToV1Mapper
.
createLicenseMap
(
report
.
licenses
);
this
.
licenses
=
report
.
licenses
.
sort
(
byLicenseNameComparator
).
map
(
V2ToV1Mapper
.
mapFromLicense
);
return
{
licenses
:
this
.
licenses
,
dependencies
:
report
.
dependencies
.
map
(
v2Dependency
=>
this
.
mapFromDependency
(
v2Dependency
)),
};
}
combine
(
licenses
)
{
return
licenses
.
reduce
(
(
memo
,
licenseId
)
=>
{
const
license
=
this
.
licenseMap
[
licenseId
];
this
.
incrementCountFor
(
license
.
name
);
if
(
memo
.
name
===
null
)
{
return
{
name
:
license
.
name
,
url
:
license
.
url
,
};
}
return
{
name
:
`
${
memo
.
name
}
,
${
license
.
name
}
`
,
url
:
''
};
},
{
name
:
null
,
url
:
null
},
);
}
incrementCountFor
(
licenseName
)
{
const
legacyLicense
=
this
.
licenses
.
find
(
license
=>
license
.
name
===
licenseName
);
if
(
legacyLicense
)
legacyLicense
.
count
+=
1
;
}
mapFromDependency
(
dependency
)
{
return
{
license
:
this
.
combine
(
dependency
.
licenses
),
dependency
:
{
name
:
dependency
.
name
,
url
:
dependency
.
url
,
description
:
dependency
.
description
,
},
};
}
static
mapFromLicense
(
license
)
{
return
{
name
:
license
.
name
,
count
:
0
};
}
static
createLicenseMap
(
licenses
)
{
return
licenses
.
reduce
((
memo
,
item
)
=>
{
memo
[
item
.
id
]
=
{
name
:
item
.
name
,
url
:
item
.
url
};
// eslint-disable-line no-param-reassign
return
memo
;
},
{});
}
}
const
DEFAULT_VERSION
=
'
1
'
;
export
default
class
ReportMapper
{
constructor
()
{
this
.
mappers
=
{
'
1
'
:
V1
,
'
2
'
:
V2
};
this
.
mappers
=
{
'
1
'
:
report
=>
report
,
'
2
'
:
report
=>
new
V2ToV1Mapper
().
mapFrom
(
report
),
};
}
mapFrom
(
reportArtifact
)
{
const
majorVersion
=
ReportMapper
.
majorVersion
(
reportArtifact
);
return
this
.
mapperFor
(
majorVersion
)
.
mapFrom
(
reportArtifact
);
return
this
.
mapperFor
(
majorVersion
)(
reportArtifact
);
}
mapperFor
(
majorVersion
)
{
return
new
this
.
mappers
[
majorVersion
]()
;
return
this
.
mappers
[
majorVersion
]
;
}
static
majorVersion
(
report
)
{
return
report
&&
report
.
version
?
report
.
version
.
split
(
'
.
'
)[
0
]
:
'
1
'
;
return
report
&&
report
.
version
?
report
.
version
.
split
(
'
.
'
)[
0
]
:
DEFAULT_VERSION
;
}
}
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