1 /++ 2 + License: MIT 3 +/ 4 5 /++ 6 + Copyright: Copyright (c) 2018, Christian Koestlin 7 +/ 8 9 /++ 10 + Authors: Christian Koestlin 11 +/ 12 13 module ponies.shields; 14 15 import ponies; 16 import std; 17 import std.experimental.logger; 18 19 class ShieldPony : Pony 20 { 21 protected UserAndProject userAndProject; 22 this() 23 { 24 userAndProject = getUserAndProject; 25 } 26 27 override bool applicable() 28 { 29 return exists("readme.org") && userAndProject.user != null && userAndProject.project != null; 30 } 31 32 override CheckStatus check() 33 { 34 return readText("readme.org").canFind(shield.strip).to!CheckStatus; 35 } 36 37 override string[] doctor() 38 { 39 if (!exists("readme.org")) 40 { 41 return ["Please add readme.org"]; 42 } 43 return []; 44 } 45 46 abstract string shield(); 47 48 override void run() 49 { 50 "Please resort your readme.org to put the shield to the right place".warning; 51 append("readme.org", shield); 52 } 53 } 54 55 class GithubShieldPony : ShieldPony 56 { 57 override string name() 58 { 59 return "Setup a link to github in readme.org"; 60 } 61 62 override string shield() 63 { 64 return "[[https://github.com/%1$s/%2$s][https://img.shields.io/github/tag/%1$s/%2$s.svg?style=flat-square]]\n" 65 .format(userAndProject.user, userAndProject.project); 66 } 67 68 override bool applicable() 69 { 70 return exists(".travis.yml"); 71 } 72 } 73 74 class CodecovShieldPony : ShieldPony 75 { 76 override string name() 77 { 78 return "Setup a link to codecov in readme.org"; 79 } 80 81 override string shield() 82 { 83 return "[[https://codecov.io/gh/%1$s/%2$s][https://img.shields.io/codecov/c/github/%1$s/%2$s/master.svg?style=flat-square]]\n" 84 .format(userAndProject.user, userAndProject.project); 85 } 86 87 override bool applicable() 88 { 89 return exists(".travis.yml"); 90 } 91 } 92 93 class TravisCiShieldPony : ShieldPony 94 { 95 override string name() 96 { 97 return "Setup a travis ci shield in readme.org"; 98 } 99 100 override string shield() 101 { 102 return "[[https://travis-ci.org/%1$s/%2$s][https://img.shields.io/travis/%1$s/%2$s/master.svg?style=flat-square]]\n" 103 .format(userAndProject.user, userAndProject.project); 104 } 105 106 override bool applicable() 107 { 108 return exists(".travis.yml"); 109 } 110 } 111 112 class GithubPagesShieldPony : ShieldPony 113 { 114 override string name() 115 { 116 return "Setup a documentation shield in readme.org"; 117 } 118 119 override string shield() 120 { 121 return "[[https://%s.github.io/%s][https://img.shields.io/readthedocs/pip.svg?style=flat-square]]\n".format( 122 userAndProject.user, userAndProject.project); 123 } 124 } 125 126 bool mightBeEmacs() 127 { 128 return exists("Cask"); 129 } 130 131 class MelpaShieldPony : ShieldPony 132 { 133 protected UserAndProject userAndProject; 134 135 this() 136 { 137 userAndProject = getUserAndProject; 138 } 139 140 override string name() 141 { 142 return "Setup a melpa shield in readme.org"; 143 } 144 145 override bool applicable() 146 { 147 return super.applicable() && mightBeEmacs; 148 } 149 150 override string shield() 151 { 152 return "[[https://melpa.org/#/%1$s][https://melpa.org/packages/%1$s-badge.svg]]".format( 153 userAndProject.project); 154 } 155 }