Skip to content

Commit

Permalink
Merge branch 'master' into badge-distance
Browse files Browse the repository at this point in the history
  • Loading branch information
notbakaneko committed Aug 5, 2020
2 parents a636c2b + 3845838 commit f2637fb
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 19 deletions.
33 changes: 31 additions & 2 deletions app/Models/ChangelogEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,20 @@ public static function guessCategory($data)
foreach ($data['pull_request']['labels'] as $label) {
$name = $label['name'];

if (!in_array(strtolower($name), $ignored, true)) {
return ucwords($name);
if (in_array(strtolower($name), $ignored, true)) {
continue;
}

$separatorPos = strpos($name, ':');
if ($separatorPos !== false) {
$name = substr($name, $separatorPos + 1);
}

if (strpos($name, ' ') === false) {
$name = str_replace('-', ' ', $name);
}

return ucwords($name);
}
}

Expand All @@ -108,6 +119,7 @@ public static function importFromGithub($data)
'created_at' => Carbon::parse($data['pull_request']['merged_at']),
'github_pull_request_id' => $data['pull_request']['number'],
'message' => $data['pull_request']['body'],
'private' => static::isPrivate($data),
'title' => $data['pull_request']['title'],
'type' => static::guessType($data),
]);
Expand All @@ -128,6 +140,23 @@ public static function importFromGithub($data)
return $entry;
}

public static function isPrivate($data)
{
static $privateCategories = [
'dependencies',
];

foreach ($data['pull_request']['labels'] as $label) {
$name = $label['name'];

if (in_array(strtolower($name), $privateCategories, true)) {
return true;
}
}

return false;
}

public static function placeholder()
{
return new static([
Expand Down
1 change: 0 additions & 1 deletion app/Transformers/BeatmapTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public function transform(Beatmap $beatmap)
'count_circles' => $beatmap->countNormal,
'count_sliders' => $beatmap->countSlider,
'count_spinners' => $beatmap->countSpinner,
'count_total' => $beatmap->countTotal,
'cs' => $beatmap->diff_size,
'deleted_at' => $beatmap->deleted_at,
'drain' => $beatmap->diff_drain,
Expand Down
4 changes: 0 additions & 4 deletions app/Transformers/UserTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,14 @@ public function transform(User $user)
'total' => $user->osu_kudostotal,
'available' => $user->osu_kudosavailable,
],
'last_visit' => json_time($user->displayed_last_visit),
'lastfm' => $user->user_lastfm,
'location' => $user->user_from,
'is_online' => $user->isOnline(),
'max_blocks' => $user->maxBlocks(),
'max_friends' => $user->maxFriends(),
'occupation' => $user->user_occ,
'playmode' => $user->playmode,
'playstyle' => $user->osu_playstyle,
'pm_friends_only' => $user->pm_friends_only,
'post_count' => $user->user_posts,
'profile_colour' => $user->user_colour,
'profile_order' => $profileCustomization->extras_order,
'skype' => $user->user_msnm,
'title' => $user->title(),
Expand Down
3 changes: 0 additions & 3 deletions config/schemas/beatmaps.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@
"countSpinner": {
"type": "long"
},
"countTotal": {
"type": "long"
},
"diff_approach": {
"type": "double"
},
Expand Down
1 change: 0 additions & 1 deletion database/factories/BeatmapFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
'version' => $faker->domainWord,
'total_length' => $length,
'hit_length' => ($length - rand(0, 20)),
'countTotal' => $hits,
'countNormal' => $hitsNormal,
'countSlider' => $hitsSlider,
'countSpinner' => $hitsSpinner,
Expand Down
2 changes: 1 addition & 1 deletion database/factories/ScoreBestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
$beatmap = factory(Beatmap::class)->create([
'playmode' => $modeInt, // force playmode to match score type
]);
$maxCombo = rand(1, $beatmap->countTotal);
$maxCombo = rand(1, $beatmap->countNormal);

return [
'user_id' => function () {
Expand Down
1 change: 0 additions & 1 deletion database/seeds/ModelSeeders/BeatmapSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ private function createBeatmap($json)
'total_length' => $json->total_length,
'hit_length' => $json->hit_length,
'bpm' => $json->bpm,
'countTotal' => $json->max_combo !== null ? $json->max_combo : 1500,
'countNormal' => round(intval($json->max_combo) - (0.2 * intval($json->max_combo))),
'countSlider' => round(intval($json->max_combo) - (0.8 * intval($json->max_combo))),
'countSpinner' => 1,
Expand Down
8 changes: 4 additions & 4 deletions database/seeds/ModelSeeders/ScoreSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function run()
//add 20 osu! Standard scores
foreach ($osuBeatmaps as $bm) {
$bms = $allBeatmapsets->find($bm->beatmapset_id);
$maxcombo = rand(1, $bm->countTotal);
$maxcombo = rand(1, $bm->countNormal);
$possible_mods = [0, 16, 24, 64, 72]; // hr, hd/hr, dt, hd/dt
$sc = App\Models\Score\Osu::create([
'user_id' => $u->user_id,
Expand Down Expand Up @@ -89,7 +89,7 @@ public function run()
//Taiko scores
foreach ($taikoBeatmaps as $bm) {
$bms = $allBeatmapsets->find($bm->beatmapset_id);
$maxcombo = rand(1, $bm->countTotal);
$maxcombo = rand(1, $bm->countNormal);
$possible_mods = [0, 16, 24, 64, 72];
$sc3 = App\Models\Score\Taiko::create([
'user_id' => $u->user_id,
Expand Down Expand Up @@ -131,7 +131,7 @@ public function run()
//Fruits scores
foreach ($fruitsBeatmaps as $bm) {
$bms = $allBeatmapsets->find($bm->beatmapset_id);
$maxcombo = rand(1, $bm->countTotal);
$maxcombo = rand(1, $bm->countNormal);
$possible_mods = [0, 16, 24, 64, 72];
$sc5 = App\Models\Score\Fruits::create([
'user_id' => $u->user_id,
Expand Down Expand Up @@ -173,7 +173,7 @@ public function run()
//Mania scores
foreach ($maniaBeatmaps as $bm) {
$bms = $allBeatmapsets->find($bm->beatmapset_id);
$maxcombo = rand(1, $bm->countTotal);
$maxcombo = rand(1, $bm->countNormal);
$possible_mods = [0, 16, 24, 64, 72]; // hr, hd/hr, dt, hd/dt
$sc7 = App\Models\Score\Mania::create([
'user_id' => $u->user_id,
Expand Down
2 changes: 1 addition & 1 deletion database/seeds/ModelSeeders/SpotlightSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private static function seedData($spotlight)
$possible_ranks = ['A', 'S', 'B', 'SH', 'XH', 'X'];

foreach ($beatmaps as $beatmap) {
$maxcombo = rand(1, $beatmap->countTotal);
$maxcombo = rand(1, $beatmap->countNormal);
$score = new $scoresClass([
'user_id' => $user->user_id,
'beatmap_id' => $beatmap->beatmap_id,
Expand Down
1 change: 0 additions & 1 deletion resources/assets/lib/interfaces/beatmap-json-extended.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export default interface BeatmapJsonExtended extends BeatmapJson {
count_circles: number;
count_sliders: number;
count_spinners: number;
count_total: number;
cs: number;
deleted_at: string | null;
drain: number;
Expand Down
83 changes: 83 additions & 0 deletions tests/Models/ChangelogEntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,87 @@ public function testConvertLegacyChangelogWithMessage()
$this->assertSame($message, $converted->title);
$this->assertNull($converted->messageHTML());
}

public function testGuessCategoryCapitalise()
{
$data = [
'repository' => ['full_name' => ''],
'pull_request' => [
'labels' => [
['name' => 'forum'],
],
],
];

$this->assertSame('Forum', ChangelogEntry::guessCategory($data));
}

public function testGuessCategoryDashToSpace()
{
$data = [
'repository' => ['full_name' => ''],
'pull_request' => [
'labels' => [
['name' => 'beatmapset-discussion'],
],
],
];

$this->assertSame('Beatmapset Discussion', ChangelogEntry::guessCategory($data));
}

public function testGuessCategoryMixedDashAndSpaceNoConversion()
{
$data = [
'repository' => ['full_name' => ''],
'pull_request' => [
'labels' => [
['name' => 'beatmapset - discussion'],
],
],
];

$this->assertSame('Beatmapset - Discussion', ChangelogEntry::guessCategory($data));
}

public function testGuessCategoryPrefixRemoval()
{
$data = [
'repository' => ['full_name' => ''],
'pull_request' => [
'labels' => [
['name' => 'area:forum'],
],
],
];

$this->assertSame('Forum', ChangelogEntry::guessCategory($data));
}

public function testIsPrivate()
{
$data = [
'repository' => ['full_name' => ''],
'pull_request' => [
'labels' => [
['name' => 'javascript'],
['name' => 'area:forum'],
],
],
];

$this->assertFalse(ChangelogEntry::isPrivate($data));

$data = [
'repository' => ['full_name' => ''],
'pull_request' => [
'labels' => [
['name' => 'javascript'],
['name' => 'dependencies'],
],
],
];

$this->assertTrue(ChangelogEntry::isPrivate($data));
}
}

0 comments on commit f2637fb

Please sign in to comment.