<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Alex Roh on Medium]]></title>
        <description><![CDATA[Stories by Alex Roh on Medium]]></description>
        <link>https://medium.com/@alex.roh?source=rss-b85a12bc03fe------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Cz-FKIoOy5W9mZQ_Bi3t8g.jpeg</url>
            <title>Stories by Alex Roh on Medium</title>
            <link>https://medium.com/@alex.roh?source=rss-b85a12bc03fe------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 13:56:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alex.roh/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Gitlab: How to automatically add code reviewers to your merge requests]]></title>
            <link>https://medium.com/@alex.roh/gitlab-how-to-automatically-add-code-reviewers-to-your-merge-requests-bcdefc2a8599?source=rss-b85a12bc03fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/bcdefc2a8599</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[gitlab]]></category>
            <dc:creator><![CDATA[Alex Roh]]></dc:creator>
            <pubDate>Wed, 29 Jun 2022 06:01:21 GMT</pubDate>
            <atom:updated>2023-08-16T00:54:10.422Z</atom:updated>
            <content:encoded><![CDATA[<p>Do you manually add code reviewers to every single merge request? Read on to discover how you can automate that process!</p><h3>Option 1: Embed a Gitlab quick action in merge request templates</h3><h4><em>How to set up</em></h4><ol><li>Create a .gitlab/merge_request_templates folder in the project root directory</li><li>In .gitlab/merge_request_templates, create a new Markdown(.md) file</li><li>Embed the /assign_reviewer quick action and the code reviewers’ Gitlab usernames:<br>/assign_reviewer @reviewer1 @reviewer2 @reviewer3 (and so on…)</li><li>Commit the changes, push to origin, and merge!</li></ol><h4>How to use</h4><ol><li>Open a new merge request or click “Edit” on an existing one</li><li>Choose your newly created template in the <em>Description</em> section</li><li>Update the description, issue ticket number, etc.</li><li>Save</li></ol><p>That’s it!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BcY7JXaXCLlNsNRw9uco_g.gif" /></figure><h3>Option 2: Utilize the Gitlab API and CI/CD</h3><h4>How to set up</h4><p>1. Create a new <a href="https://docs.gitlab.com/ee/user/group/">Gitlab group</a> or a subgroup of an existing group and add code reviewers to the group. You can skip this step if you already have a group or wish to hard-code the reviewer IDs in the CI/CD pipeline job</p><p>2. Create a .gitlab-ci.yml file in the project root directory</p><p>3. Configure a new job to run in merge request pipelines with rules. Add a “set up merge request&quot; stage, if applicable</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8f4b3359ff35c86238ddae12db806867/href">https://medium.com/media/8f4b3359ff35c86238ddae12db806867/href</a></iframe><p><em>Optional: Use </em><a href="https://docs.gitlab.com/ee/ci/yaml/#ruleschanges"><em>rules:changes</em></a><em> to have more granular control over which changes trigger the job. If you have an </em><em>android and </em><em>ios directory in your repository, for example, you can create two separate jobs that assign Android and iOS code reviewers, respectively, depending on what changes are included in the merge request</em></p><p>4. In before_script, instruct the job to install <a href="https://stedolan.github.io/jq/">jq</a>, a JSON processor, on the runner before it runs. Depending on your runner’s environment, you may have to use a different package manager from the one used below</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7ca093349ac5e61fdd434c3e499cc026/href">https://medium.com/media/7ca093349ac5e61fdd434c3e499cc026/href</a></iframe><p>5. Write a script that assigns code reviewers to your merge request via the Gitlab API</p><blockquote><strong><em>Step 1)</em></strong><em> Fetch the code reviewer list via the </em><a href="https://docs.gitlab.com/ee/api/members.html"><em>Gitlab API</em></a><em>. If you wish to hard-code the reviewer list, skip this step</em></blockquote><blockquote>Tip #1:<em> Make sure your token has read API access to your group. </em><a href="https://docs.gitlab.com/ee/ci/variables/predefined_variables.html"><em>CI_JOB_TOKEN</em></a><em>, the default token generated for every job, does not have API read access</em></blockquote><blockquote>Tip #2:<strong> </strong><em>If you created a subgroup of an existing group, make sure you strictly isolate </em><a href="https://docs.gitlab.com/ee/user/project/members/"><em>direct members from inherited members</em></a><em> and use the appropriate API</em></blockquote><blockquote><strong><em>Step 2)</em></strong><em> Extract the reviewers’ Gitlab IDs, </em><strong>not the usernames</strong><em>, from the JSON response and put them in an array. If you wish to hard-code the reviewer list, hard-code an array of the code reviewers’ Gitlab IDs instead</em></blockquote><blockquote><strong><em>Step 3)</em></strong><em> Use the </em><a href="https://docs.gitlab.com/ee/api/merge_requests.html#update-mr"><em>Gitlab API</em></a><em> to add the reviewers to your merge request</em></blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/01a4eeaf993e03671909d3eac433fc2c/href">https://medium.com/media/01a4eeaf993e03671909d3eac433fc2c/href</a></iframe><p>6. Commit the changes, push to origin, and merge!</p><h4>How to use</h4><p>Just create a new merge request!</p><h4><strong>Sample .gitlab-ci.yml</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e1f9e929fa7987ad692def6a8da620a0/href">https://medium.com/media/e1f9e929fa7987ad692def6a8da620a0/href</a></iframe><p>And there you have it! Two options to automatically assign code reviewers to your merge requests.</p><p>If you’ve done something similar or know of any alternatives, let me know in the comments section!</p><p>Thanks for reading.</p><p>If you find this content valuable,</p><ol><li>👏</li><li>Share it with your coworkers</li><li><a href="https://www.buymeacoffee.com/alexroh">Come fuel me up with coffee</a>!</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bcdefc2a8599" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TypeScript Enums: What they are and why you should avoid them]]></title>
            <link>https://medium.com/@alex.roh/typescript-enums-what-they-are-and-why-you-should-avoid-them-20aabfcd601f?source=rss-b85a12bc03fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/20aabfcd601f</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[enum]]></category>
            <dc:creator><![CDATA[Alex Roh]]></dc:creator>
            <pubDate>Mon, 06 Jun 2022 04:51:16 GMT</pubDate>
            <atom:updated>2023-08-16T01:00:01.327Z</atom:updated>
            <content:encoded><![CDATA[<iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F12079644&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fryan-reynolds-but-why-gif-12079644&amp;image=https%3A%2F%2Fc.tenor.com%2FjGgmfDOxmuMAAAAC%2Fryan-reynolds-but-why.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/025fd5b479677c2c478ffc0a449a9c57/href">https://medium.com/media/025fd5b479677c2c478ffc0a449a9c57/href</a></iframe><p>Enum, or enumerated type, is a data type that defines a set of constants, and its use is a common phenomenon in many programming languages such as C, C#, and Java. It can be a great tool to achieve type safety, readability, and maintainability when used in the right circumstances. Enum in TypeScript, though, is a bit different and trickier to use. Here’s why.</p><p><strong>1. Antithetical to TypeScript’s Design Goals</strong></p><p>TypeScript is a superset of JavaScript that does not have a runtime. It features static type-checking, and the TypeScript compiler transpiles your TypeScript code to JavaScript code that is actually run.</p><p>Enums, interestingly, are non-existent in JavaScript. Enums are “one of the few features TypeScript has which is not a <em>type-level extension</em> of JavaScript,” ¹ coercing TypeScript to conserve enums with JavaScript code that compromises key design goals of TypeScript — to “emit clean, idiomatic, recognizable JavaScript code” and to “use a consistent, fully erasable, structural type system.” ²</p><pre>// <strong>TypeScript Code</strong><br>enum CompassDirection {<br> North, <br> East,<br> South,<br> West,<br>}</pre><pre>/* <br><strong>Transpiled JavaScript Code</strong><br>TypeScript has to conserve the enum with ugly, unidiomatic JavaScript code to run at runtime. TypeScript enums are not &quot;fully eraseable&quot;! 👎<br>*/<br>var CompassDirection;<br>(function (CompassDirection) {<br>    CompassDirection[CompassDirection[&quot;North&quot;] = 0] = &quot;North&quot;;<br>    CompassDirection[CompassDirection[&quot;East&quot;] = 1] = &quot;East&quot;;<br>    CompassDirection[CompassDirection[&quot;South&quot;] = 2] = &quot;South&quot;;<br>    CompassDirection[CompassDirection[&quot;West&quot;] = 3] = &quot;West&quot;;<br>})(CompassDirection || (CompassDirection = {}));</pre><p>Technically, you <em>can</em> mitigate this problem by writing a <strong>const enum</strong>. Unlike with regular enums, TypeScript inlines all const enum values instead of generating JavaScript code. It’s a valid workaround but there’s one big caveat: using const enums “can lead to safety issues when you import a const enum from someone else’s TypeScript code.” ³ Because TypeScript inlines const enum values at compile time, your version of the enum may differ from the author’s if the enum author updates his enum after you’ve compiled your TypeScript code.</p><p><strong>2. Difficult to Achieve Complete Type Safety</strong></p><p>With enums in TypeScript, you can map strings to strings or strings to numbers. If the values aren’t set explicitly, TypeScript infers the values as numbers for you. Let’s take another look at CompassDirection, a strings-to-numbers enum.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e464a3fa1651ed0f7b43e9586d7cb89a/href">https://medium.com/media/e464a3fa1651ed0f7b43e9586d7cb89a/href</a></iframe><p>Strings-to-numbers enums aren’t type-safe!</p><p>Strings-to-numbers enums also support reverse mapping, which allows you to look up the keys via values.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7fda120076fbe35069760ac2e1e6bf83/href">https://medium.com/media/7fda120076fbe35069760ac2e1e6bf83/href</a></iframe><p>We cannot achieve type safety with strings-to-numbers enums, because all numbers, enumerated explicitly or not, can be assigned to a strings-to-numbers enum.</p><p>To achieve type safety, we can write a strings-to-strings enum instead.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ea228bdfbfacf853730f5f1894123f5/href">https://medium.com/media/9ea228bdfbfacf853730f5f1894123f5/href</a></iframe><p>Looks good! We got errors as expected.</p><p>In terms of robustness and maintainability, though, the enum isn’t great because as soon as you or your teammate mix string and number values, you will lose type safety.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9fe456ebf3a67df303dd07eb483a9d01/href">https://medium.com/media/9fe456ebf3a67df303dd07eb483a9d01/href</a></iframe><p>Whatever enums you write, they must be strictly “strings-to-strings” to maintain type safety in your software.</p><p><strong>3. Solid Alternatives</strong></p><p>TypeScript offers robust alternatives that you can use in lieu of enums.</p><p><em>Union Types (TypeScript version 1.4 and newer)</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ad8d497509c5490c4a49c47fdfebd5e4/href">https://medium.com/media/ad8d497509c5490c4a49c47fdfebd5e4/href</a></iframe><p><em>Const Assertions (TypeScript version 3.4 and newer)</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/78e04b40a34a24161b9c709fca604b7a/href">https://medium.com/media/78e04b40a34a24161b9c709fca604b7a/href</a></iframe><p>Unlike enums that are conditionally type-safe, union types and const assertions guarantee type safety!</p><p><strong>Conclusion</strong></p><p>In theory, an enum is a great tool for achieving type safety, readability, and maintainability in your software. Specifically in TypeScript, however, enums fail to meet TypeScript’s design goals, are tricky to get right, and can be replaced by more robust alternatives that you can use to achieve the same goals.</p><p>To me, TypeScript enum is a great reminder to always evaluate what tools may be best to achieve my goals <em>in the immediate circumstances</em>, rather than defaulting to what I’m already familiar with.</p><p>Thanks for reading!</p><p><strong>References</strong></p><p>[1] <em>Handbook — Enums</em>. (2022, May 30). TypeScript. <a href="https://www.typescriptlang.org/docs/handbook/enums.html">https://www.typescriptlang.org/docs/handbook/enums.html</a></p><p>[2] <em>TypeScript Design Goals · microsoft/TypeScript Wiki</em>. (2020, February 26). GitHub. <a href="https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals">https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals</a></p><p>[3] Cherny, B. (2019). <em>Programming TypeScript: Making Your JavaScript Applications Scale</em> (1st ed.). O’Reilly Media.</p><p><strong>Interesting Side Note</strong></p><p>A senior member of Microsoft’s TypeScript team commented that enums are a <a href="https://github.com/vkurchatkin/typescript-vs-flow/issues/6#issue-197401087">“semi-legacy construct”</a> in TypeScript.</p><blockquote>If you find this content valuable and would like to see more, <a href="https://www.buymeacoffee.com/alexroh">come fuel me up with coffee!</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20aabfcd601f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>